• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Someone want to take a look at this and figure out why this tree implementation won't work?

Decaying tree.

What does not work mean here? Does it segfault, does it produce the incorrect answer? What's it supposed to do and what does it actually do?

Depending on those answers the issue might be that you never initialise product in your Expression struct, so when you push them into the array at the end you have undefined values for expr.product.

There's no reason not to initialise product when you create an Expression I believe since it looks like you never change the values of the dependent variables. So something like:

Code:
struct Expression
{
    int twoPower;
    int threePower;
    int product;
public:
    Expression(int two, int three) {
        twoPower = two; 
        threePower = three;
        product = pow(3.0, threePower) * pow(2.0, twoPower);
    }
    int get_product() const {
        return product;
    }
    int get_two() const {
        return twoPower;
    }
    int get_three() const {
        return threePower;
    }
};

In this case the stored expressions for me look like this for n = 5:
myExpressions =
{twoPower=0 threePower=0 product=1 }
{twoPower=1 threePower=0 product=2 }
{twoPower=2 threePower=0 product=4 }
{twoPower=0 threePower=1 product=3 }
{twoPower=1 threePower=1 product=6 }
{twoPower=2 threePower=1 product=12 })
Which might be what you are trying to do since it looks like the correct product for 2^twoPower * 3^threePower?
 

RELAYER

Banned
I'm doing a project and could use some help.

I'm using a microcontroller and C++ and I'm making an electronic lock. There is a memory chip (eeprom?) so that the user can decide their own lock combination and have it stored. The mbed interfaces with the memory chip using I2C. I'm not familiar with this function so I'm trying to figure out how to write and read data into and from the memory chip using I2C.

I really have no idea and I can't find any examples online or if I did, it doesn't look like C to me.

This is what I tried so far but it doesn't seem to care what I choose to write.

Code:
#include "mbed.h"

I2C i2c(p9,p10);
Serial pc(USBTX, USBRX);
const int addr = 0x52;
const int code = 0x11;
char recd_val = 0;


int main () {
    while(1) {
        i2c.start();
        i2c.write(addr);
        i2c.write(code);
        i2c.stop();
        wait(1);
        i2c.start();
        i2c.write(addr);
        recd_val = i2c.read(code);
        i2c.stop();
        pc.printf("%d\n\r", recd_val);
        }
}
 
Hating my assembly work right now so much. Problem wants me to make a recursive call without using any conditional statements except loop. The worst part is there's almost 0 resources on assembly and no one would want to write a recursive call without if conditions anyways.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Hating my assembly work right now so much. Problem wants me to make a recursive call without using any conditional statements except loop. The worst part is there's almost 0 resources on assembly and no one would want to write a recursive call without if conditions anyways.

This is my main annoyance with theory comp sci classes.
Gotta do what you gotta do though.
 

mooooose

Member
Hating my assembly work right now so much. Problem wants me to make a recursive call without using any conditional statements except loop. The worst part is there's almost 0 resources on assembly and no one would want to write a recursive call without if conditions anyways.

I've never written a recursive function in anything in my life that didn't have a conditional fro when the base case is reached. How the hell do you even do that?
 
I've never written a recursive function in anything in my life that didn't have a conditional fro when the base case is reached. How the hell do you even do that?


Here is the problem word for word;

"Write a program that calls a recursive procedure. Inside this procedure, add 1 to a counter so you can verify the number of times it executes. Run your program with a debugger, and at the end of the program, check the counter's value. Put a number in ECX that specifies the number of times you want to allow the recursion to continue. Using only the LOOP instruction (and no other conditional statements from later chapters), find a way for the recursive procedure to call itself a fixed number of times."

ECX usually decrements each time a loop goes through in assembly (the book uses MASM through Visual Studio), but I fail to see how the loop would stop a procedure from calling itself since it would just start a new loop and another call each time. The chapter itself is over procedures and the runtime stack, so I'm assuming the answer deals with those concepts. Any solution I can imagine isn't actually using real recursion where the function calls itself.
 

maeh2k

Member
Here is the problem word for word;

"Write a program that calls a recursive procedure. Inside this procedure, add 1 to a counter so you can verify the number of times it executes. Run your program with a debugger, and at the end of the program, check the counter's value. Put a number in ECX that specifies the number of times you want to allow the recursion to continue. Using only the LOOP instruction (and no other conditional statements from later chapters), find a way for the recursive procedure to call itself a fixed number of times."

ECX usually decrements each time a loop goes through in assembly (the book uses MASM through Visual Studio), but I fail to see how the loop would stop a procedure from calling itself since it would just start a new loop and another call each time. The chapter itself is over procedures and the runtime stack, so I'm assuming the answer deals with those concepts. Any solution I can imagine isn't actually using real recursion where the function calls itself.

I'm still not clear on how the procedure is supposed to work, but my first approach would be:
Code:
function f()
    loop
        +1
        f()

It should work, since all loops share the count in ecx. Then again, it's a really dumb punction. Using a loop that isn't actually looping is all kinds of wrong.
 

luoapp

Member
I'm doing a project and could use some help.

I'm using a microcontroller and C++ and I'm making an electronic lock. There is a memory chip (eeprom?) so that the user can decide their own lock combination and have it stored. The mbed interfaces with the memory chip using I2C. I'm not familiar with this function so I'm trying to figure out how to write and read data into and from the memory chip using I2C.

Just a general suggestion, it's probably useful to find the chip model and read its documentations.
 

RELAYER

Banned
Just a general suggestion, it's probably useful to find the chip model and read its documentations.

I have it. It's around 40 pages and most of it seems totally irrelevant to what I'm trying to do. My instructor specified a few tables that are relevant, but they are hardware oriented and I don't understand how to practically translate that information into software application. All I can gather is that I apparently need a "pointer" for an address, and then somehow use an array to possible write in hexadecimal characters. Maybe. As you can probably tell from my explanation, I'm totally lost.

Other than that all I know about the chip is that once you write something in, the data stays there even without power. So if i could just write it in and then be able to read it out again to check it against the user's input, I'd be good.

It seems simple and it's something I know how to do through other means, but I just don't understand this whole "I2C" concept. So I'm mainly having trouble with the syntax for using an I2C object, how to write in data and read data out specifically.

So basically my trouble isn't so much with the chip itself, but rather how to control an I2C object in C++.

Which you'd think would be easy to just look up online, but I haven't had any success finding examples where I2C is used with a memory device.
 

luoapp

Member
I have it. It's around 40 pages and most of it seems totally irrelevant to what I'm trying to do. My instructor specified a few tables that are relevant, but they are hardware oriented and I don't understand how to practically translate that information into software application. All I can gather is that I apparently need a "pointer" for an address, and then somehow use an array to possible write in hexadecimal characters. Maybe. As you can probably tell from my explanation, I'm totally lost.

Other than that all I know about the chip is that once you write something in, the data stays there even without power. So if i could just write it in and then be able to read it out again to check it against the user's input, I'd be good.

It seems simple and it's something I know how to do through other means, but I just don't understand this whole "I2C" concept. So I'm mainly having trouble with the syntax for using an I2C object, how to write in data and read data out specifically.

So basically my trouble isn't so much with the chip itself, but rather how to control an I2C object in C++.

Which you'd think would be easy to just look up online, but I haven't had any success finding examples where I2C is used with a memory device.

ok, what's the chip?
 

luoapp

Member

You need to read the documentations. According figure 2 of this application note http://ww1.microchip.com/downloads/en/AppNotes/01113B.pdf, the writing part basically is like this
Code:
const int dev_addr =  ??;   // dev_addr = 1010xxx0;  xxx is the A0-A2 ping of 24LC01.
const int onchip_addr = 0x52;
const char code = 0x11;
char write_payload[3];

write_payload[0] = onchip_addr >> 8;
write_payload[1] = onchip_addr;
write_payload[2] = code;

i2c.start();
i2c.write(dev_addr, write_payload, 3);
i2c.stop();
 

RELAYER

Banned
I'm familiar with that example you posted, it's the same as pretty much every example I've found online, but I just don't understand what is going on in that code and I haven't seen it explained simply yet. I'm sure I'm missing something obvious but it remains mysterious to me. That's my problem. All the address stuff and the write function is confusing to me. 'll just email my instructor. Sorry.
 

squidyj

Member
I'm implementing a vector matrix and math library and I'm trying to figure out how best I can add constructors or constructing functions when I'm using class templates to specify vector type and length.

I also want to implement swizzling for my most commonly used vector lengths 2, 3, 4

for swizzling i can represent contiguous in order subvectors simply with an anonymous union on my vector( ie v.xyz or v.xy or v.yz in a 4 component vector). I can live without more expressive swizzling but I can't have my vectors requiring any more storage than their n components.
 

wwm0nkey

Member
Okay so me and a few of my class mates are having a problem. We are all in Programming I in college and we are on our 2nd to last assignment in Java and we need to use getters and setters in our new program.....except our teacher never really went over them so we are all kind of feeling fucked right now.

The program has to open up a JOptionPane and when we type in a number and hit ok the number is added to the sub total and the item count goes up by one.

I get how the program will work but a lot of us are lost at using the getters and setters and using them in the JOptionPane.
 

kingslunk

Member
Okay so me and a few of my class mates are having a problem. We are all in Programming I in college and we are on our 2nd to last assignment in Java and we need to use getters and setters in our new program.....except our teacher never really went over them so we are all kind of feeling fucked right now.

The program has to open up a JOptionPane and when we type in a number and hit ok the number is added to the sub total and the item count goes up by one.

I get how the program will work but a lot of us are lost at using the getters and setters and using them in the JOptionPane.

You use getters and setters to set and get variables.

For example:
Code:
class Foo{
     protected int total;
     int getTotal(){
          return this.total;
     }

     void setTotal(int valueFromJOptionPanel)
     {  
            this.total += valueFromJOptionPanel;
     }

}
 
I'm implementing a vector matrix and math library and I'm trying to figure out how best I can add constructors or constructing functions when I'm using class templates to specify vector type and length.

I also want to implement swizzling for my most commonly used vector lengths 2, 3, 4

for swizzling i can represent contiguous in order subvectors simply with an anonymous union on my vector( ie v.xyz or v.xy or v.yz in a 4 component vector). I can live without more expressive swizzling but I can't have my vectors requiring any more storage than their n components.

Not really my area of expertise but I did see this: http://google.github.io/mathfu/ recently and maybe it could be of use?

just having issue with Class stuff

Code:
#include <iostream>
using namespace std;
 
class Human{
    char *name;
    int age;
    float height;
    float weight;
    
public:
Human (char *N, int A, float H, float W);
void Prints () const;
void Set (char *N, int A, float H, float W);
  
};

int main(){
Human myObj;
myObj.Prints();
myObj.Set("Ronaldo", 28, 185.0, 85.0);
myObj.Prints();
}

Never got it working in Dev C++ but my friend got it work in Xcode

Any idea why?

Is there a reason you do Human myObj and not Human* myObj = new Human()? Also what is your compiler or run time error?
 

Water

Member
I'm implementing a vector matrix and math library and I'm trying to figure out how best I can add constructors or constructing functions when I'm using class templates to specify vector type and length.

I also want to implement swizzling for my most commonly used vector lengths 2, 3, 4

for swizzling i can represent contiguous in order subvectors simply with an anonymous union on my vector( ie v.xyz or v.xy or v.yz in a 4 component vector). I can live without more expressive swizzling but I can't have my vectors requiring any more storage than their n components.
Check out how GLM does it.
https://github.com/g-truc/glm
 

Water

Member
Is there a reason you do Human myObj and not Human* myObj = new Human()?
Weird question. Good C++ programming practice dictates you should default to automatic memory management ("Human myObj") and avoid manual memory management unless you have a specific reason.

Even if you actually had a reason to reserve the memory manually, naked pointer and "new" are not good style. We have unique_ptr, shared_ptr, make_shared etc. for that stuff.
 
Weird question. Good C++ programming practice dictates you should default to automatic memory management ("Human myObj") and avoid manual memory management unless you have a specific reason.

Even if you actually had a reason to reserve the memory manually, naked pointer and "new" are not good style. We have unique_ptr, shared_ptr, make_shared etc. for that stuff.

Must be a C++ 11 thing I'm not used to. I've been trying to learn more about C++ 11 by using Cocos2D-X which uses the auto stuff but even then I still make use of new.

Shouldn't you then use auto MyObject?

Still the fact that you're using this stuff is probably why you had issues compiling in one IDE and not another.
 

wwm0nkey

Member
Yay I now understand getters and setters and my project is done. thanks.

Would be nice if our teacher at least gave us examples....but oh well.
 
Must be a C++ 11 thing I'm not used to. I've been trying to learn more about C++ 11 by using Cocos2D-X which uses the auto stuff but even then I still make use of new.

Shouldn't you then use auto MyObject?

Still the fact that you're using this stuff is probably why you had issues compiling in one IDE and not another.

No, that's just plain C++. auto doesn't have anything to do with new (or lack thereof). It just lets the compiler figure out the type of the value, it works like this:
Code:
// The following two are equivalent:
auto obj = MyObject();
MyObject obj;

// The following two are also equivalent, but you don't generally need to use 'new'
auto obj = new MyObject();
MyObject* obj = new MyObject();

// You can also do this
for (auto iter = vector.begin(); iter != vector.end(); ++iter) { }
// In C++11 you can actually also just do the following:
for (const auto& value: vector) { }
You only very rarely need to use raw pointers and 'new' in C++.
 

Water

Member
Must be a C++ 11 thing I'm not used to. I've been trying to learn more about C++ 11 by using Cocos2D-X which uses the auto stuff but even then I still make use of new.
No, defaulting to automatic memory management has always been good C++ style. A beginner in C++ shouldn't touch new/delete/pointers at all for a while, especially if they're coming off C (which gives one a massive load of bad habits when it comes to writing C++). Before you understand templates, containers, iterators etc. well, you aren't at a level where you should try something complicated enough to require manual memory management.

The _ptr classes I mentioned are C++11 standard library stuff, but they are only relevant where you'd otherwise use new and delete, so you shouldn't need them all the time either. And you've always been able to use 3rd party smart pointers or to write your own. Alexandrescu's "Modern C++ Design" has an entire chapter that walks you through the design tradeoffs involved in writing your own smart pointers; this book is from 2000, nearly 15 years old. The C++11 smart pointers are descendants (unique_ptr) and carbon copies (shared_ptr) of the pointer classes in the Boost libraries, and those have been available for 15 years as well.

C++11 does make a difference, though. Thanks to new core features like move semantics, you can get away without pointers/new/delete in even more situations than before, so there's even less reason to tolerate them these days.
 

Slavik81

Member
Must be a C++ 11 thing I'm not used to. I've been trying to learn more about C++ 11 by using Cocos2D-X which uses the auto stuff but even then I still make use of new.

Shouldn't you then use auto MyObject?

Still the fact that you're using this stuff is probably why you had issues compiling in one IDE and not another.
C++11 auto can only be used when the type of the variable can be inferred from context, like when you're assigning to it. So, auto MyObject = new ExampleType; is valid, but auto MyObject; has no context that suggests what type is should be.

No, that's just plain C++. auto doesn't have anything to do with new (or lack thereof). It just lets the compiler figure out the type of the value, it works like this:
Code:
// The following two are equivalent:
auto obj = MyObject();
MyObject obj;
They are basically equivalent, but I feel like being pedantic, so I'll point out that there are subtle differences.

The first will create a temporary instance of MyObject using the default constructor. If MyObject is a POD type and has no default constructor, it will be zero-initialized. Then it creates an instance of MyObject called obj using the copy or move constructor. This copy can be optimized away, even if it changes the observable behaviour of the program (like if you put print statements in the copy/move constructors), but if you mark the class as non-copyable it will always be a compiler error.

The second just creates an instance of MyObject using the default constructor. Even if MyObject is a PoD type and has no default constructor, it will NOT be zero-initialized.
 

Water

Member
For modern C++ I'd generally suggest using these syntax forms:
Code:
MyObject obj; // optionally add {} to reinforce that default init is intended
MyObject obj{some, constructor, arguments};
auto obj = MyObject{some, constructor, arguments};
They avoid a number of issues that are possible with the older forms, eg. the Most Vexing Parse problem.
 
Do y'all recommend writing minimal function declarations and building up or making everything read-only and erasing down? Or is this a bad question and I should know before I write anything?

i.e.
Code:
int foo(int, int) {
}
vs.
Code:
const int foo(const int, const int) const {
}
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
No, defaulting to automatic memory management has always been good C++ style. A beginner in C++ shouldn't touch new/delete/pointers at all for a while, especially if they're coming off C (which gives one a massive load of bad habits when it comes to writing C++). Before you understand templates, containers, iterators etc. well, you aren't at a level where you should try something complicated enough to require manual memory management.

The _ptr classes I mentioned are C++11 standard library stuff, but they are only relevant where you'd otherwise use new and delete, so you shouldn't need them all the time either. And you've always been able to use 3rd party smart pointers or to write your own. Alexandrescu's "Modern C++ Design" has an entire chapter that walks you through the design tradeoffs involved in writing your own smart pointers; this book is from 2000, nearly 15 years old. The C++11 smart pointers are descendants (unique_ptr) and carbon copies (shared_ptr) of the pointer classes in the Boost libraries, and those have been available for 15 years as well.

C++11 does make a difference, though. Thanks to new core features like move semantics, you can get away without pointers/new/delete in even more situations than before, so there's even less reason to tolerate them these days.

This is funny because the beginner prog. and intro to alg. classes at this new university teach in C++ and instruct us to directly use pointers, create them with new, and manually delete them.

It didn't seem right to me. We are just now starting to work with templates.
I've been much happier with Javascript personally.
 

upandaway

Member
I'm only a few weeks into the Intro to CS course but I have to say, I don't like C at all. At all at all. It's just as bad as it seemed from when I read the C book you guys recommended.
We're doing C and Python at the same time in the course which makes it seem that much worse too.
 
No, defaulting to automatic memory management has always been good C++ style. A beginner in C++ shouldn't touch new/delete/pointers at all for a while, especially if they're coming off C (which gives one a massive load of bad habits when it comes to writing C++). Before you understand templates, containers, iterators etc. well, you aren't at a level where you should try something complicated enough to require manual memory management.

The _ptr classes I mentioned are C++11 standard library stuff, but they are only relevant where you'd otherwise use new and delete, so you shouldn't need them all the time either. And you've always been able to use 3rd party smart pointers or to write your own. Alexandrescu's "Modern C++ Design" has an entire chapter that walks you through the design tradeoffs involved in writing your own smart pointers; this book is from 2000, nearly 15 years old. The C++11 smart pointers are descendants (unique_ptr) and carbon copies (shared_ptr) of the pointer classes in the Boost libraries, and those have been available for 15 years as well.

C++11 does make a difference, though. Thanks to new core features like move semantics, you can get away without pointers/new/delete in even more situations than before, so there's even less reason to tolerate them these days.

Man, I don't remember any of this being taught this way when I was in college 10 years ago. I always learned to do things at Object* myObject = new Object();, I guess when you spend the past two years programming in Obj-C and Unity C# you miss out on this stuff.

No, that's just plain C++. auto doesn't have anything to do with new (or lack thereof). It just lets the compiler figure out the type of the value, it works like this:
Code:
// The following two are equivalent:
auto obj = MyObject();
MyObject obj;

// The following two are also equivalent, but you don't generally need to use 'new'
auto obj = new MyObject();
MyObject* obj = new MyObject();

// You can also do this
for (auto iter = vector.begin(); iter != vector.end(); ++iter) { }
// In C++11 you can actually also just do the following:
for (const auto& value: vector) { }
You only very rarely need to use raw pointers and 'new' in C++.

Right, I knew this about auto but for some reason I didn't know the other part about declaring objects as Obj myObj and not calling new.

Do y'all recommend writing minimal function declarations and building up or making everything read-only and erasing down? Or is this a bad question and I should know before I write anything?

i.e.
Code:
int foo(int, int) {
}
vs.
Code:
const int foo(const int, const int) const {
}

Learning and understanding Const correctness I think is one of those things that starts setting beginners apart. Read this for some help: http://stackoverflow.com/questions/136880/sell-me-on-const-correctness
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I'm only a few weeks into the Intro to CS course but I have to say, I don't like C at all. At all at all. It's just as bad as it seemed from when I read the C book you guys recommended.
We're doing C and Python at the same time in the course which makes it seem that much worse too.

What the hell? Why??
 

upandaway

Member
What the hell? Why??
In their words, it's literally because Python is so easy and Google friendly that they basically just jammed it into the course.

I'm not envying any of the peeps who never programmed before because it's not a very bright idea, and they're having a tough time.
 

Kevyt

Member
In their words, it's literally because Python is so easy and Google friendly that they basically just jammed it into the course.

I'm not envying any of the peeps who never programmed before because it's not a very bright idea, and they're having a tough time.


That's unusual. Almost every intro CS course starts with C/C++, python and other languages are later on.
 
C++11 auto can only be used when the type of the variable can be inferred from context, like when you're assigning to it. So, auto MyObject = new ExampleType; is valid, but auto MyObject; has no context that suggests what type is should be.


They are basically equivalent, but I feel like being pedantic, so I'll point out that there are subtle differences.

The first will create a temporary instance of MyObject using the default constructor. If MyObject is a POD type and has no default constructor, it will be zero-initialized. Then it creates an instance of MyObject called obj using the copy or move constructor. This copy can be optimized away, even if it changes the observable behaviour of the program (like if you put print statements in the copy/move constructors), but if you mark the class as non-copyable it will always be a compiler error.

The second just creates an instance of MyObject using the default constructor. Even if MyObject is a PoD type and has no default constructor, it will NOT be zero-initialized.

Ah, thanks. I always forget those weird C++isms when I don't use the language for a couple of months. (which is the case right now)
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
In their words, it's literally because Python is so easy and Google friendly that they basically just jammed it into the course.

I'm not envying any of the peeps who never programmed before because it's not a very bright idea, and they're having a tough time.

This is one the stupidest explanations I've heard.

Holy shit.

I'm sorry you have to go through that, and I feel bad for the people in your class that are experiencing programming for the first time. That is a horrible introduction.

That's unusual. Almost every intro CS course starts with C/C++, python and other languages are later on.

Actually, a large amount of courses are switch to Python/Java first, and then teaching more advanced languages like C/C++ later on.
Hopefully that trend continues.
C/C++ is a terrible language to start on in my honest opinion.
 
So a little resume advice needed. I assume some of the electives I took and some of the higher level courses I took would be something to put on my resume? Plus projects and languages and frameworks I know, right?

From what I have seen C/C++ is being phased out of most undergrad programs.

where I'm at, python is the intro classes, and then a mandatory class on C and Assembly and then one on Operating Systems which is obviously C oriented. Other than that it's what ever you want to use as long as the professor can compile and run it (obviously).

Kinda makes the C and Assembly class see a lot of drop off actually..
 
Anyone know any simplish GitHub projects I could contribute to? Looking for a job is really, really depressing and I'm becoming especially desperate to get my foot in the door.
 

Slavik81

Member
Do y'all recommend writing minimal function declarations and building up or making everything read-only and erasing down? Or is this a bad question and I should know before I write anything?

i.e.
Code:
int foo(int, int) {
}
vs.
Code:
const int foo(const int, const int) const {
}
I don't mark anything that is being passed by value as const. It doesn't affect the caller, so it seems extranious.

Also, the compiler might warn about the second signature. It's never any use to return 'const int'. It just doesn't do anything. ("warning: type qualifiers ignored on function return type")

Ah, thanks. I always forget those weird C++isms when I don't use the language for a couple of months. (which is the case right now)
I've worked with C++ for 6+ years and I'm still learning new things. Fortunately, those sorts of details almost never actually matter.
 

OceanBlue

Member
where I'm at, python is the intro classes, and then a mandatory class on C and Assembly and then one on Operating Systems which is obviously C oriented. Other than that it's what ever you want to use as long as the professor can compile and run it (obviously).

Kinda makes the C and Assembly class see a lot of drop off actually..

I'm in the same situation. I learned Java for the Intro classes, and the rest of the classes afterwards just assumed you had knowledge of Java. I've done C/Assembly for embedded programming classes and C++ (new/delete/pointers, so more like C with classes?) for one class so we could learn pointers. You don't even need to take the embedded programming courses if you're doing a Computer Science track as opposed to a Computer Engineering track, which a lot of people choose to do so they can avoid the courses.
 

Quasar

Member
A question about Java and Logger

Just where do the events written go? I assumed I'd be able to view them in the Winodws Event Viewer, but that doesn't seem to be the case.

So if I have a property of my class like this:

Code:
private static final Logger log = Logger.getLogger( MyPlayingZoneLoginDialog.class.getName() );

and a command inside a catch block like:

Code:
log.log( Level.SEVERE, e.toString(), e );

where does it go?
 

squidyj

Member
GLM only implements vectors of size 1 2 3 and 4, wherea's i'm looking to implement vectors of arbitrary size, however I think I figured it out.

If I use a couple templated functions i should be able to recursively peel the first argument from my list of arguments, and sum the number of components. By using different functions for first values i can grab an individual element, arrays of elements, or vectors of elements, and determine the length of the final vector which can be constructed in the zero argument base case and then populated with the data from the arguments as I move up the chain. I'm only concerned about the ability of the compiler to infer array length if a user created an array from a pointer with new. I'm not really clear on that.

I had another concern but then I read up on template and now I know they have partial ordering which should be enough,

I can solve the swizzling problem with swizzle functions that return temporary objects which operate on pointers to the original vector components (with redefined operators to smooth some syntax) but it leaves the disparate v.xy and v.yx() when i would prefer v.yx
 
Anyone know any simplish GitHub projects I could contribute to? Looking for a job is really, really depressing and I'm becoming especially desperate to get my foot in the door.

No offense, but "please throw this dog a bone" is a pretty bad way to approach this situation. I understand that you are frustrated, but it's very unlikely that a simplish GitHub project falls from the sky and on to your lap.

Did you know that GitHub has a section called Explore (https://github.com/explore), which lists all kinds of types of projects, listed by categories, trending topics and so on? What I'd suggest is:

1) Go to GitHub Explore
2) Sort by your programming language(s) of choice
3) Look at the projects
4) Find the ones that interest you personally. If any of them don't,
sorry you might be on the wrong field :p
5) Look if they accept contributions (which they often do)
6) Sort the issues for pick-me-ups, beginner tasks and so on.
7) Pick one and start working on it.
 
A question about Java and Logger

Just where do the events written go? I assumed I'd be able to view them in the Winodws Event Viewer, but that doesn't seem to be the case.

So if I have a property of my class like this:

Code:
private static final Logger log = Logger.getLogger( MyPlayingZoneLoginDialog.class.getName() );

and a command inside a catch block like:

Code:
log.log( Level.SEVERE, e.toString(), e );

where does it go?

By default it goes to the console because there is a console handler. If you want it to go to a file you need to give it a FileHandler.

I haven't really used the java.util.Logger as I use log4j though.
 

phoenixyz

Member
After all this C++ talk I kinda have the urge to refresh my knowledge in that area. Are there any good introductions into best practices including the more recent features of the language?
 

Ambitious

Member
I have to do a small university project in JavaScript/Node.js, which I'm not that familiar with. I need to loop through an array of files and folders, find a folder with a specific name and return its id (= supplying it to the callback function). If no such folder exists, it should be created. Here's the relevant snippet:

Code:
function(..., fn) {
  var id = null;

  items.forEach(function(item) {
    if(item.name === folderName) {
      id = item.id;
    }
  });
 
  if(id) {
    fn(id);
  } else {
    createFolder(folderName, fn);
}

This sucks. There's no need to keep iterating through the array when the folder has already been found. I tried the following:
Code:
function(..., fn) {
  items.forEach(function(item) {
    if(item.name === folderName) {
      fn(item.id);
      return;
    }
  });
    
  createFolder(folderName, fn);
}

Much more concise. But for some reason, createFolder is always called, even when a folder is found. Had I simply called the callback function, I would understand that - but there's a return afterwards. Could someone give me a hint, please?
 
I have to do a small university project in JavaScript/Node.js, which I'm not that familiar with. I need to loop through an array of files and folders, find a folder with a specific name and return its id (= supplying it to the callback function). If no such folder exists, it should be created. Here's the relevant snippet:

Code:
function(..., fn) {
  var id = null;

  items.forEach(function(item) {
    if(item.name === folderName) {
      id = item.id;
    }
  });
 
  if(id) {
    fn(id);
  } else {
    createFolder(folderName, fn);
}

This sucks. There's no need to keep iterating through the array when the folder has already been found. I tried the following:
Code:
function(..., fn) {
  items.forEach(function(item) {
    if(item.name === folderName) {
      fn(item.id);
      return;
    }
  });
    
  createFolder(folderName, fn);
}

Much more concise. But for some reason, createFolder is always called, even when a folder is found. Had I simply called the callback function, I would understand that - but there's a return afterwards. Could someone give me a hint, please?

In your second version, your "return" only exits the forEach-function, not the fn()-function it's wrapped in.
 
No offense, but "please throw this dog a bone" is a pretty bad way to approach this situation. I understand that you are frustrated, but it's very unlikely that a simplish GitHub project falls from the sky and on to your lap.

Did you know that GitHub has a section called Explore (https://github.com/explore), which lists all kinds of types of projects, listed by categories, trending topics and so on? What I'd suggest is:

1) Go to GitHub Explore
2) Sort by your programming language(s) of choice
3) Look at the projects
4) Find the ones that interest you personally. If any of them don't,
sorry you might be on the wrong field :p
5) Look if they accept contributions (which they often do)
6) Sort the issues for pick-me-ups, beginner tasks and so on.
7) Pick one and start working on it.

Thanks this is what I was looking for. When I meant simplish I meant that someone can just jump in and find a place they can contribute without having 5 years experience in the field etc.
 

D4Danger

Unconfirmed Member
This sucks. There's no need to keep iterating through the array when the folder has already been found.

you could use Array.some instead of Array.forEach

the return is only returning from the current forEach iteration. It will finish doing those then call createFolder regardless. Your first example is closer to what you want.
 
Thanks this is what I was looking for. When I meant simplish I meant that someone can just jump in and find a place they can contribute without having 5 years experience in the field etc.

Hopefully you'll find something that will pique your interest! And good luck with the job searching!
 
Top Bottom