Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asking for Tips: Writing readable, beautiful code
#1
Hello everyone!
So I have been facing a lot of problem with communicating my code to other fella programmers. Mainly because I was never concerned about how my code looks as long as it works which, I admit, has always been a mistake from my side. General notes I've got from others are:
1-You work with headers like a noob.
2-Comment more.
3-Comment less (and that is when I actually try to "comment more" in my code).
4-You're suffering from longlinegitis; the lines of codes are too long.


1-I don't quite understand what they mean there. The way everyone does it is weirder in my opinion. In my case, I've got a .cpp file for my main. The rest are .h files because they are just function definitions which are used in the main. Others seem to have both a .h AND a .cpp file for almost everything. .h are made to store the function parameters, while the cpp contains the definitions. I just can't get why do they do this. Don't know, but perhaps, can this be something to do with how a programmer should read other sources? Would be interested to know if there is a pattern, as I often can't get what file in the source should I start from (the main).

2-I have to admit that it is mostly me being lazy there.

3-And this happened when I tried commenting. People said I am explaining obvious things there:
http://pastebin.com/sQj4nMja
In general, what kind of lines do I need to comment? I mean, I can't know the level of the programmer who's going to read my code, can I? People vary in their abilities to read a piece of code.

4-The problem is, I sometimes just NEED to call a function with so many parameters, which in turn leads to such long liners. A solution to this problem is to simply store all the parameters in an array, and using it as the parameter instead. But what if I have all the parameters of different data types? Is there a way I can pack such things together? Or is it something I just have to avoid? Any tips on how I can manage length of a line of a code?


P.S: When I call a function and use a certain class's object as a parameter, will this involve copying the whole object to be used? Now what if I use a pointer to the object; will this mean I will only be pushing the 8-digit address and that is it?
I've also noticed that a debugger usually gets stuck when you try to find the value of something like this:
Code:
class1->arrayofobjects[class1->someindexint]->an_int_arrayinclass[class2->someindexint]
Now that had my wondering whether it is because this kind of call is a bit expensive memory-wise (is it?). I am always questioning when it comes to low level processes such as the above. In general, low-level is supposed to be faster. But is that true in the above case?

I would really, REALLY appreciate any advice that would help me write in a better way. Thanks in advance!

Edit: A source by me:
http://pastebin.com/PkLxyQEB
http://pastebin.com/pzQVXfUT
http://pastebin.com/vbj1MCFn
http://pastebin.com/ig4pkQfw
[Image: signature.png]
A-Engine: A new beat em up game engine inspired by LF2. Coming soon

A-Engine Dev Blog - Update #8: Timeout

Reply
Thanks given by:


Messages In This Thread
Asking for Tips: Writing readable, beautiful code - by A-Man - 03-10-2014, 07:49 PM



Users browsing this thread: 1 Guest(s)