• 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

Granadier

Is currently on Stage 1: Denial regarding the service game future
Oh no, I wish it was elective. It's a mandatory course.

I work in SAP implementatinos so believe me, Prolog is like the last thing I'd take would it be an elective one, haha.

Are you studying in Germany by chance?

Also is it really common for CSCI departments to be behind the times, (outside of the cutting edge universities)? My university's introductory courses were all C++ and required compiling on 25 year old Solaris systems.
 

xero273

Member
Not sure if this is the correct place, but I just found out that for a button I have. The html changes depending on if you have admin access. If you don't have admin access, the button has an attribute of disabled. It works, but the problem is if you bring up the developer console in IE and delete the disabled attribute the button becomes clickable again.. how do I avoid this?

Thanks
 

Saprol

Member
Not sure if this is the correct place, but I just found out that for a button I have. The html changes depending on if you have admin access. If you don't have admin access, the button has an attribute of disabled. It works, but the problem is if you bring up the developer console in IE and delete the disabled attribute the button becomes clickable again.. how do I avoid this?
I would suggest including code on the server side to check that the user actually has the proper privileges before going through with whatever action the button performs.
 

wolfmat

Confirmed Asshole
Not sure if this is the correct place, but I just found out that for a button I have. The html changes depending on if you have admin access. If you don't have admin access, the button has an attribute of disabled. It works, but the problem is if you bring up the developer console in IE and delete the disabled attribute the button becomes clickable again.. how do I avoid this?

Thanks

You should verify that the user may invoke the action that the button press is supposed to fire independently of the button.

The button click itself should only communicate the desire to do something.
It being disabled should communicate beforehand that this desire will not be fulfilled.

So the button is inside some HTML, and then you do a POST or whatever. This POST is received by for example PHP code on the server, and that PHP code should know _who_ pressed the button, and whether that is something that person or role is allowed to do. It should then not do the action if that's not the case, and preferably also give back an error.

So for instance, you could render a standard 403 error if someone is not supposed to click the button, but does it anyway.
 

injurai

Banned
Anybody have any experience with Machine Assembly Language?

I spent 8 consecutive hours laying out code in pencil for something that I could write in 2 minutes in any other language in Y86. Ran perfectly on my first try. Only thing I've written in assembly though and Y86 is the easy version.

But that's all the experience I have. It's really becoming less and less relevant to anyone who doesn't write compiles or works on LLVM.

I may recall some knowledge or be able to point you in the right direction.
 
I spent 8 consecutive hours laying out code in pencil for something that I could write in 2 minutes in any other language in Y86. Ran perfectly on my first try. Only thing I've written in assembly though and Y86 is the easy version.

But that's all the experience I have. It's really becoming less and less relevant to anyone who doesn't write compiles or works on LLVM.

I may recall some knowledge or be able to point you in the right direction.
These guys didn't get the message. Some of them are writing their own bootloaders and everything.
 

sca2511

Member
Ah, I'm so frustrated with my current assignment(C++). We have to implement Johnson Trotter's algorithm to a |N| set of numbers and I'm so lost. I understand what I'm supposed to be doing, but I can't wrap my head around implementing it.
 

Nesotenso

Member
I was hoping someone would clear the purpose of using the shebang character for certain scripting languages.

For python scripts the practice is to type, #!usr/bin/env python

Now # is also used for comments in python, so I was wondering if that line was being read which led me to this answer.

http://askubuntu.com/questions/238002/is-bin-sh-read-by-the-interpreter

If I am reading the answer right, the first line in such scripts is for the OS and not the interpreter. so I don't have to invoke python helloworld.py when running the script.
I can do it by using ./helloworld.py as long as the shebang line is present.
but this didn't work for me and it seems I still have to make the file an executable using chmod +x helloworld.py and then run ./
is there a way to avoid invoking the interpreter while executing a script? and is the shebang really necessary?
 

Slavik81

Member
is there a way to avoid invoking the interpreter while executing a script? and is the shebang really necessary?
The interpreter is the thing that understands your python code and performs the actions specified by your script. So, no, you can't avoid invoking it.
 

injurai

Banned
I was hoping someone would clear the purpose of using the shebang character for certain scripting languages.

For python scripts the practice is to type, #!usr/bin/env python

Now # is also used for comments in python, so I was wondering if that line was being read which led me to this answer.

http://askubuntu.com/questions/238002/is-bin-sh-read-by-the-interpreter

If I am reading the answer right, the first line in such scripts is for the OS and not the interpreter. so I don't have to invoke python helloworld.py when running the script.
I can do it by using ./helloworld.py as long as the shebang line is present.
but this didn't work for me and it seems I still have to make the file an executable using chmod +x helloworld.py and then run ./
is there a way to avoid invoking the interpreter while executing a script? and is the shebang really necessary?

This should expand on most all your questions http://www.wikiwand.com/en/Shebang_(Unix)

But yeah, an interpreter is what is actually parsing and carrying out your script. Just as you need a compiler for compiled languages. Really it's a shorthand to specify that the following script should be passed to a certain interpreter.

The precedent of this is mostly in shell scripting. Where you can specify one of many different shells that you want interpreting your script. You have to make your file executable so the OS runs it in the first place. Where as calling "python my_script" the python interpreter is already a compiled executable.

That is pretty much the short of it, but you're probably wondering "why offer that alternative at all?"

It mostly has to do with the impetus that shell scripting is trying to achieve. Scripting languages exist to mostly stick together various processes, tools, libraries and orchestra them together without any of the subcomponents needing to interact. By including the shell or interpreter in the script itself, each script is self-contained. No need to bother know which shell each script is meant to run on. Just treat the script like any other executable in your code. It really just cleans things up and compartmentalizes.
 

Renekton

Member
Also is it really common for CSCI departments to be behind the times, (outside of the cutting edge universities)? My university's introductory courses were all C++ and required compiling on 25 year old Solaris systems.
At least for me the Solaris systems were somewhat speedy back when in uni days. I don't miss VI though, especially the elitism that came with it.
 
I was hoping someone would clear the purpose of using the shebang character for certain scripting languages.

For python scripts the practice is to type, #!usr/bin/env python

Now # is also used for comments in python, so I was wondering if that line was being read which led me to this answer.

http://askubuntu.com/questions/238002/is-bin-sh-read-by-the-interpreter

If I am reading the answer right, the first line in such scripts is for the OS and not the interpreter. so I don't have to invoke python helloworld.py when running the script.
I can do it by using ./helloworld.py as long as the shebang line is present.
but this didn't work for me and it seems I still have to make the file an executable using chmod +x helloworld.py and then run ./
is there a way to avoid invoking the interpreter while executing a script? and is the shebang really necessary?

You know how in Windows you can double click a file and the action taken depends on the file extension? For example, pdfs open in acrobat, html files in your browser, etc. It's basically that. When you try to execute that script in your shell, the shell uses that first line to figure out what program actually understands the script.
 

Nesotenso

Member
You know how in Windows you can double click a file and the action taken depends on the file extension? For example, pdfs open in acrobat, html files in your browser, etc. It's basically that. When you try to execute that script in your shell, the shell uses that first line to figure out what program actually understands the script.

so say I didn't use the shebang line and I used chmod to make my file an executable, then I would still have to use the interpreter, right?

edit: I answered my own question by trying it out

The interpreter is the thing that understands your python code and performs the actions specified by your script. So, no, you can't avoid invoking it.

I was talking about explicitly typing it out.
But i figured it out by trying. if have an executable py script with the shebang line I can just execute it with ./
 

Tater Tot

"My God... it's full of Starch!"
I spent 8 consecutive hours laying out code in pencil for something that I could write in 2 minutes in any other language in Y86. Ran perfectly on my first try. Only thing I've written in assembly though and Y86 is the easy version.

But that's all the experience I have. It's really becoming less and less relevant to anyone who doesn't write compiles or works on LLVM.

I may recall some knowledge or be able to point you in the right direction.

I understand your pain. I have a project due for my Machine Assembly Class. I also spent about 4 hours translating Java to Pseudocode. All that just so I can translate it over to Assembler. I am just having trouble with my program because it is my first time using loops in assembler.
 

wolfmat

Confirmed Asshole
I understand your pain. I have a project due for my Machine Assembly Class. I also spent about 4 hours translating Java to Pseudocode. All that just so I can translate it over to Assembler. I am just having trouble with my program because it is my first time using loops in assembler.
Conditional jmps, eax (/rax) is iterator, you're good. (In most cases.)
 
I understand your pain. I have a project due for my Machine Assembly Class. I also spent about 4 hours translating Java to Pseudocode. All that just so I can translate it over to Assembler. I am just having trouble with my program because it is my first time using loops in assembler.

Seems like a strange way to approach the problem. Can't you just sit down and write it in assembly? What's the actual assignment?
 

injurai

Banned
Seems like a strange way to approach the problem. Can't you just sit down and write it in assembly? What's the actual assignment?

Never just sit down and write in assembly. That is methodology reserved for the gods. Do your pseudo code like a good little programmer.
 
Never just sit down and write in assembly. That is methodology reserved for the gods. Do your pseudo code like a good little programmer.

Well I mean it's for an assembly language class, so presumably the problem is simple enough that a pure assembly solution should be feasible. You only need like 5-10 instructions in assembly. mov, xor, push, pop, and, or, jump, test, sub, add, and the god of all instructions, lea
 

Phrynobatrachus

Neo Member
Ok, I'm just straight up fucking baffled at whatever's going on with my code right now. Same code I mentioned in my other post, but filled out. I'm positive I have the right idea but my output is wrong. I'm reading a 2d array in, and creating a struct for each non-negative, non-zero element. Here's the terminal output when I run this. The lists for nodes 0 and 1 seem to be created correctly, but the other nodes are showing some wrong numbers in their lists, despite those numbers being correct when assigned to the list. Can anyone figure out why? I apologize for the kinda convoluted question, and it's probably some super simple mistake, but I feel like I'm banging my head against a wall here.

SJiP92p.png
 
Ok, I'm just straight up fucking baffled at whatever's going on with my code right now. Same code I mentioned in my other post, but filled out. I'm positive I have the right idea but my output is wrong. I'm reading a 2d array in, and creating a struct for each non-negative, non-zero element. Here's the terminal output when I run this. The lists for nodes 0 and 1 seem to be created correctly, but the other nodes are showing some wrong numbers in their lists, despite those numbers being correct when assigned to the list. Can anyone figure out why? I apologize for the kinda convoluted question, and it's probably some super simple mistake, but I feel like I'm banging my head against a wall here.

SJiP92p.png

Staring at code is almost never the best way to figure out why something doesn't work. Install a graphical debugger, step through the code, and you should have it figured out in no time. Being able to use a debugger is also an extremely valuable skill, so it definitely is in your best interest to try. If you're on Windows, download Visual Studio Express, make a new project, paste this code into there, compile, press F9 to put a breakpoint, F5 to run, then just step and watch the value of the variables at each point. If you're on Linux or Unix, you should have GDB, which is a little more obtuse, but sitll pretty easy to use for simple applications like this.
 

Phrynobatrachus

Neo Member
Staring at code is almost never the best way to figure out why something doesn't work. Install a graphical debugger, step through the code, and you should have it figured out in no time. Being able to use a debugger is also an extremely valuable skill, so it definitely is in your best interest to try. If you're on Windows, download Visual Studio Express, make a new project, paste this code into there, compile, press F9 to put a breakpoint, F5 to run, then just step and watch the value of the variables at each point. If you're on Linux or Unix, you should have GDB, which is a little more obtuse, but sitll pretty easy to use for simple applications like this.

Good point, I'll check out gdb and work on it some more. Thanks.
 
rust now in beta!

Yeah! I've been using Rust on and off for about a year now and the language has changed so much, almost everything for the better. I've been solving Rosalind problems in Rust and it's a joy to use and also very fast. (Github repository for the code) The borrow/type checker can be a bit of a hassle at the start, but the error messages have become much clearer lately and it's almost always there for a reason.

@Phrynobatrachus: If you're on Windows, get Visual Studio Community Edition, that's the newer free version that has all of the features of all the earlier Express versions combined and also has support for plug-ins. The VS debugger is probably the best one currently for C++ code. GDB is very powerful, but it always feels like a hassle to use it, especially when you're not already good with it.
 

Mr.Mike

Member
I'm coming to really dislike the super abbreviated/shortened variable names that I tend to find in C code. In my own code now I'm starting to type out full(er) names in snake case and I find it much nicer and easier to read. I do probably spend a lot more time reading the code than typing it in the first place, and decent text editors will have those pop-up suggestion things so I never really type a full variable twice anyway.

I've also started writing my curly braces on the next line instead of line of.

Anyone else had changing styles over time?
 

injurai

Banned
Yeah! I've been using Rust on and off for about a year now and the language has changed so much, almost everything for the better. I've been solving Rosalind problems in Rust and it's a joy to use and also very fast. (Github repository for the code) The borrow/type checker can be a bit of a hassle at the start, but the error messages have become much clearer lately and it's almost always there for a reason.

@Phrynobatrachus: If you're on Windows, get Visual Studio Community Edition, that's the newer free version that has all of the features of all the earlier Express versions combined and also has support for plug-ins. The VS debugger is probably the best one currently for C++ code. GDB is very powerful, but it always feels like a hassle to use it, especially when you're not already good with it.

I dabbled with it a bit on and off. Partly do to lack of free time, and partly because it was changing too much for me. Now that it's beta I plan to really dive in and start learning it more fully. In my short time using it, rustc is my favorite compiler to argue with. It's error messages are really great and appreciated. So far just been playing around in a linux environment. I was going to start going through handmade hero which has you work on windows with Visual Studio Community Edition. But I was going to use c for that project. I was planning on going through project euler myself. Never heard of Rosalind, looks similar.

I really feel rust is the first language to fall in a new modern watershed. Most other languages have felt like false hype and promise to me. Even languages older than me seemed to just shift problems around.

I'm coming to really dislike the super abbreviated/shortened variable names that I tend to find in C code. In my own code now I'm starting to type out full(er) names in snake case and I find it much nicer and easier to read. I do probably spend a lot more time reading the code than typing it in the first place, and decent text editors will have those pop-up suggestion things so I never really type a full variable twice anyway.

I've also started writing my curly braces on the next line instead of line of.

Anyone else had changing styles over time?

I tend to use camel case for variables, snake case for everything else. Snake case is easier to read though. One thing that I really hate is putting the opening brace on the next line. I only do that for method declarations. Everything else it's on the same line. If I had to be consistent I would start putting the method braces on the same line. I find it incredibly unclean looking to put them on the next line. But I actually started out more like you in this regard and shifted my tastes to putting them on the same line.

Next argument is probably tabs vs spaces. I'm a tabs guy and apparently I'm wrong for thinking so. Just so much easier to manage and write.
 

Two Words

Member
I saw this article the other day how supposedly far too many programmers fail to correctly design this simple program. And that the majority that do get it right, make at least one mistake first.

So here's the program. Print numbers from 100 to 1. You can only write code in the for loop and nothing before or after it. You fill the rest after the first third of the for loop header. Seems kind of weird for it to be missed so much.

for (int i = 0
 
Next argument is probably tabs vs spaces. I'm a tabs guy and apparently I'm wrong for thinking so. Just so much easier to manage and write.
There's not really a functional difference in any modern IDE.

Yeah, super-abbreviated C-style names can sometimes be about as helpful as naming your variables a,b,c,d,... I feel like they're just a remnant of the days before autocompletion.
 

injurai

Banned
I saw this article the other day how supposedly far too many programmers fail to correctly design this simple program. And that the majority that do get it right, make at least one mistake first.

So here's the program. Print numbers from 100 to 1. You can only write code in the for loop and nothing before or after it. You fill the rest after the first third of the for loop header. Seems kind of weird for it to be missed so much.

for (int i = 0

for (int i = 0; i > -100; i--) {
println( -1 * (i - 1) );
}

What constitutes correct though? In most cases I feel like the programmer has no real sense of what the compiler would be doing. It be interesting to see how others approach the simplest of things. They way I did it is probably not what I would actually do, but you made me think a bit harder with your challenge.
 
I saw this article the other day how supposedly far too many programmers fail to correctly design this simple program. And that the majority that do get it right, make at least one mistake first.

So here's the program. Print numbers from 100 to 1. You can only write code in the for loop and nothing before or after it. You fill the rest after the first third of the for loop header. Seems kind of weird for it to be missed so much.

for (int i = 0

My favorite solution:
Code:
for (int i=0; ; i++) { // Wait for overflow.
    if (i >= -100 && i < 0)
        printf("%i", -i);
    if (i == -1)
        break;
}
 
Yeah, super-abbreviated C-style names can sometimes be about as helpful as naming your variables a,b,c,d,... I feel like they're just a remnant of the days before autocompletion.
Really old C compilers used to impose a maximum limit of 8 characters that you could put into a function or a variable name. I want to say that the "i, j, k", "w, x, y, z" and "a, b, c" variable names started with FORTRAN, but that goes far beyond the limits of my knowledge when it comes to programming languages.

Part of that limitation was imposed by a lack of memory in the hardware, at the time. To an extent, also a problem with cramming information into a single line of code on a single, very low res screen.
 

Mr.Mike

Member
The octal solution is amazing. But here.
Code:
for (int i = 0 ; i < 100 ; i++ )
{
  switch(i)
  {
    case 0:
      printf("100\n");
    case 1:
      printf("99\n");
    case 2:
      printf("98\n");
    // and so on
    default:
      return i;
  }
}

But that's a silly solution. Something better might go.

Code:
for i in 0 to 100
    if i == 0
        continue
    n_string = integer_to_string_function( i )
    append n_string to result_string
    if i == 100
         reverse the result_string
         print the result_string to standard output

Interviewers love reversed strings right?
 

Two Words

Member
Hah I like the octal method, Slavik.

Have you guys ever figured out a bug in your program in a dream? I had that happen in our previous project. It was a pretty surreal moment when I woke up with the answer to my issue.
 

wolfmat

Confirmed Asshole
I saw this article the other day how supposedly far too many programmers fail to correctly design this simple program. And that the majority that do get it right, make at least one mistake first.

So here's the program. Print numbers from 100 to 1. You can only write code in the for loop and nothing before or after it. You fill the rest after the first third of the for loop header. Seems kind of weird for it to be missed so much.

for (int i = 0
Code:
for(int i = 0; i<1; i *= 12) {
    printf("numbers from 100 to 1\n");
    break;
}
 
I am having some rather trivial issues with UI text updating in my visual C# program.

I have two check boxes. If both are checked, the text attached to the textbox updates. If only the first one is checked, then it also updates the text.

And my code looks like this.
Code:
if (Checkbox.Checked && Checkbox2.Checked)
        {
            Checkbox.Text = "Both boxes checked";
        }
if (!Checkbox2.Checked)
            {
                Checkbox.Text = "First box checked";
            }
But what I'm actually getting is very inconsistent because even if the condition is met, nothing happens unless the other box is clicked.
It's under the CheckChanged event for the first check box. What is the correct way to actually do this?
 

Pegasus Actual

Gold Member
I am having some rather trivial issues with UI text updating in my visual C# program.

I have two check boxes. If both are checked, the text attached to the textbox updates. If only the first one is checked, then it also updates the text.

And my code looks like this.
Code:
if (Checkbox.Checked && Checkbox2.Checked)
        {
            Checkbox.Text = "Both boxes checked";
        }
if (!Checkbox2.Checked)
            {
                Checkbox.Text = "First box checked";
            }
But what I'm actually getting is very inconsistent because even if the condition is met, nothing happens unless the other box is clicked.
It's under the CheckChanged event for the first check box. What is the correct way to actually do this?
Well, the logic needs to execute in the event handler for both boxes. So I suppose you could outsource it to its own function that gets called from both event handlers, or just register the same event handler for both the checkboxes and handle everything there. Also from the snippet of logic you posted I'm not sure why Checkbox2 not being checked guarantees that Checkbox is checked, though maybe there is other logic.
 
I'm coming to really dislike the super abbreviated/shortened variable names that I tend to find in C code. In my own code now I'm starting to type out full(er) names in snake case and I find it much nicer and easier to read. I do probably spend a lot more time reading the code than typing it in the first place, and decent text editors will have those pop-up suggestion things so I never really type a full variable twice anyway.

I've also started writing my curly braces on the next line instead of line of.

Anyone else had changing styles over time?
Absolutely. My style's kind of its own code, but everything is trying to logically parse elements into an instantly recognizable form.

snake case -> local variables
snake case upper case -> global variables/#defines
camel case -> structs/classes
pascal case -> functions/namespaces

namespace_name::some_class.random_function(long_struct_name.local_variable); turns into NamespaceName::someClass.RandomFunction(longStructName.local_variable); which is just a bit more sane to me.

Also, new line for ending curly. Same line with space for beginning curly.
 

wolfmat

Confirmed Asshole
I like this one for the "for-loop goes from 100 to 0" thing:
Code:
for(int i=0; i < 101; printf("%d\n",(100-i++)));
 
I'm coming to really dislike the super abbreviated/shortened variable names that I tend to find in C code. In my own code now I'm starting to type out full(er) names in snake case and I find it much nicer and easier to read. I do probably spend a lot more time reading the code than typing it in the first place, and decent text editors will have those pop-up suggestion things so I never really type a full variable twice anyway.

I've also started writing my curly braces on the next line instead of line of.

Anyone else had changing styles over time?

To answer your question, I actually switched from snake_case long ago to camelCase andI ended up kind of hating snake_case. That underscore is just so inconvenient to type, lol. Plus, I guess I feel like it's unnecessary filler. I still use it for CONSTANT_VALUES, though.



In general, to be honest, naming conventions is one of the main things which is making it hard for me to feel comfortable enough to start coding in C/C++.

As someone who codes a lot of Java, I feel like everything in Java is neatly organized, well named, and also nicely documented with Javadoc (which you don't have to use often because there's a lot of self-documentation). Every Java file contains one class which is the same name as the Java file, and only code and data related to the class. It makes it hard for me to jump into C/C++ because a lot of it is just so hard for me to understand just by looking at it.

I mean... I look at code like this and think, "What the heck is all this?":
Code:
        winClass.lpszClassName = "MY_WINDOWS_CLASS";
        winClass.cbSize = sizeof(WNDCLASSEX);
        winClass.style = CS_HREDRAW | CS_VREDRAW;
        winClass.lpfnWndProc = WndProc;
        winClass.hInstance = hInstance;
        winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV);
        winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        winClass.cbClsExtra = 0;
        winClass.cbWndExtra = 0;
(Source: http://code.google.com/p/vbjin-ovr/source/browse/main.cpp)

Whenever I see code like that, my brain truly just shuts off and I can't absorb it.


I happened across this style guide as I wrote this post:
http://geosoft.no/development/cppstyle.html
If everything in C/C++ were coded in such a way, I'd have an easier time feeling comfortable enough with the language to actually write some code.
 

MrCuddle

Member
I mean... I look at code like this and think, "What the heck is all this?":
Code:
        winClass.lpszClassName = "MY_WINDOWS_CLASS";
        winClass.cbSize = sizeof(WNDCLASSEX);
        winClass.style = CS_HREDRAW | CS_VREDRAW;
        winClass.lpfnWndProc = WndProc;
        winClass.hInstance = hInstance;
        winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV);
        winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        winClass.cbClsExtra = 0;
        winClass.cbWndExtra = 0;
(Source: http://code.google.com/p/vbjin-ovr/source/browse/main.cpp)

Whenever I see code like that, my brain truly just shuts off and I can't absorb it.

WinAPI is a bit messy at first sight, but it kinda starts making sense after using it for a while.

The C++ standard library feels just fine to me though.
 
To answer your question, I actually switched from snake_case long ago to camelCase andI ended up kind of hating snake_case. That underscore is just so inconvenient to type, lol. Plus, I guess I feel like it's unnecessary filler. I still use it for CONSTANT_VALUES, though.



In general, to be honest, naming conventions is one of the main things which is making it hard for me to feel comfortable enough to start coding in C/C++.

As someone who codes a lot of Java, I feel like everything in Java is neatly organized, well named, and also nicely documented with Javadoc (which you don't have to use often because there's a lot of self-documentation). Every Java file contains one class which is the same name as the Java file, and only code and data related to the class. It makes it hard for me to jump into C/C++ because a lot of it is just so hard for me to understand just by looking at it.

I mean... I look at code like this and think, "What the heck is all this?":
Code:
        winClass.lpszClassName = "MY_WINDOWS_CLASS";
        winClass.cbSize = sizeof(WNDCLASSEX);
        winClass.style = CS_HREDRAW | CS_VREDRAW;
        winClass.lpfnWndProc = WndProc;
        winClass.hInstance = hInstance;
        winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV);
        winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        winClass.cbClsExtra = 0;
        winClass.cbWndExtra = 0;
(Source: http://code.google.com/p/vbjin-ovr/source/browse/main.cpp)

Whenever I see code like that, my brain truly just shuts off and I can't absorb it.


I happened across this style guide as I wrote this post:
http://geosoft.no/development/cppstyle.html
If everything in C/C++ were coded in such a way, I'd have an easier time feeling comfortable enough with the language to actually write some code.

I know what you mean. A lot of game code like the one you linked is some weird mix between C and C++ (also known as C++98 without templates and RAII) and in addition, this has a lot of WinAPI code and pretty much no comments at all. There's plenty of nice C++ code though. The code of the STL itself is pretty much unreadable, at least for me, but using it is pretty straightforward. Same goes for most Boost libraries.
 
To answer your question, I actually switched from snake_case long ago to camelCase andI ended up kind of hating snake_case. That underscore is just so inconvenient to type, lol. Plus, I guess I feel like it's unnecessary filler. I still use it for CONSTANT_VALUES, though.



In general, to be honest, naming conventions is one of the main things which is making it hard for me to feel comfortable enough to start coding in C/C++.

As someone who codes a lot of Java, I feel like everything in Java is neatly organized, well named, and also nicely documented with Javadoc (which you don't have to use often because there's a lot of self-documentation). Every Java file contains one class which is the same name as the Java file, and only code and data related to the class. It makes it hard for me to jump into C/C++ because a lot of it is just so hard for me to understand just by looking at it.

I mean... I look at code like this and think, "What the heck is all this?":
Code:
        winClass.lpszClassName = "MY_WINDOWS_CLASS";
        winClass.cbSize = sizeof(WNDCLASSEX);
        winClass.style = CS_HREDRAW | CS_VREDRAW;
        winClass.lpfnWndProc = WndProc;
        winClass.hInstance = hInstance;
        winClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
        winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winClass.lpszMenuName = MAKEINTRESOURCE(IDC_CV);
        winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        winClass.cbClsExtra = 0;
        winClass.cbWndExtra = 0;
(Source: http://code.google.com/p/vbjin-ovr/source/browse/main.cpp)

Whenever I see code like that, my brain truly just shuts off and I can't absorb it.


I happened across this style guide as I wrote this post:
http://geosoft.no/development/cppstyle.html
If everything in C/C++ were coded in such a way, I'd have an easier time feeling comfortable enough with the language to actually write some code.

I would argue that that's easier to understand than a lot of java code. You can tell by looking exactly what it's doing, which is just setting some fields of a struct to some values. Presumably it has to do with creating a window. You might not know what all those values mean, but that's just because you haven't looked at the documentation for the API being called.
 
Top Bottom