Re: What about your brains?
identation and good comments are the way to go, even if you have some stupid huge ass fuction for some stupid reason if you have a comments on the generical mechanic of the function it is so so much easyer to understand where the error could be. heck my comments get - function name, n
Re: What about your brains?
Quote:
Originally Posted by
evill33t
with a well prepared uml diagram you wont have 1000 variables ;) at least not global or in one method
true true ;-) i wish only my brain would produce good schemes >.>
Sometimes i confussed by my own ideas and whole diagram is worth less than crap that i made this morning
Re: What about your brains?
Quote:
Originally Posted by
Daevius
As for using functions, even if a part of the code is only used once I sometimes tend to make a function for it, so the original code is better organised and you can in one flash see what it does (else you have to find out what like 10 lines do, while with a function name you can easily see what it does -> 1 line). In the functions you can concentrate on just that part of the code. Works quite well :)
I've always started out coding thinking 'right' im going to code this in the cleanest way possible, Unfortunatly i tend to start out well and then Once i "get into it" i tend to not want to pause and keep writing out Functions/Methods I just tend to storm ahead. :( And the resulting code is... Well.. You can imagine :tongue:
...A Good 1000+ line Function? :tongue:
More ontopic:
Of course i get around the problem of Variable names in general by just declaring them In scope by just Surrounding the 'Bit of Code' (That should _Really_ be a function :tongue:) with curly braces
But yeah, debugging my code without an IDE would be a nightmare... And as for viewing my code from a year ago? -Shudder- Doesn't bear thinking about.
People, for the love of god - Learn good coding practises now (Indentation is the very basis of good coding practise - Go further! Much Further! :tongue:)
~ Jeax
Re: What about your brains?
FF, the style you use is exactly what I self-learned. I'd still use it only if style guidelines at our courses didn't require us to use even more whitespace. I really don't understand where all that comes from because IMO it certainly doesn't make the code any more readable. Especially I was physically hurt when I found out that I can't write a single statement after an IF on the same line, and not even on the second, but I would have to place it inside brackets. Now it hurts to have to write a program of 30 lines on to 60, only because "style" requires to use enough whitespace! Oh well, I'm not going to complain about this because the guys in big shoes say this is the way to go and my complaint will not make my grades any better, so I'll just go as they say. :tongue:
Anyhow what I said earlier is in line with what every other (semi-)experienced coder in this thread said: use good coding style. It does help.
In fact, in my view I was a pretty good coder already before starting these noob courses at uni, so far I haven't learnt any coding techniques at all but I was forced to learn some style, and to my big surprise it helped not only to comprehend my code afterwards but also to develop a whole program without having to error-check it once. I got hardly any new coding experience, but only because of learning to keep up with *a* style I can now write any software and more often than not, it always compiles without errors and bugs on the first try.
Long-ass post. Sorry it was my night out for a change. :tongue:
Re: What about your brains?
i totaly prefer this The Apache Portals Site - Coding Standards style :P
and you dont need to take care of formating at all every ide should haave an auto formater and for the vi guys i guess there are enough cli tools avaible
my favorite ide for everything is eclipse
ctrl+shift+f ftw :P
Re: What about your brains?
Quote:
Originally Posted by
FragFrog
No it bloody well isn't :tongue: K&R style saves you a lot of useless whitespace, especially if you also put the opening brace on the same line for functions.
Aye, whenever not using whitespaces looks better, I don't use the whitespaces. But I still try to group things. Like variables with the same subject/relevance (no white lines in between) or functions that do similair things.
PS: Java style commenting? Whenever I watch the source code of something I always first clear out those comments, as they look messy to me and take to much space to see in one view what it all does...but yeah, all preferance ;)
Quote:
Originally Posted by
Jeax
I've always started out coding thinking 'right' im going to code this in the cleanest way possible, Unfortunatly i tend to start out well and then Once i "get into it" i tend to not want to pause and keep writing out Functions/Methods I just tend to storm ahead. :( And the resulting code is... Well.. You can imagine :tongue:
...A Good 1000+ line Function? :tongue:
Oh yes, same for me.
I was building a gui class in C and SDL to display a console (aye guys, its not VB ;)) with text lines and text submition. Took me several days, as I had to rebuild it once and clean it all up twice. Once I get into it I want to finish it, and when some things take too long (like creating order in your programming) I forgot what the original problem was ^^. So I just rush, which is bad as I'll have to rewrite everything (though copy and paste does most ^^). But in the end the result is quite good :)
EDIT:
Here we go: SourceForge.net: Artistic Style
Re: What about your brains?
Quote:
Originally Posted by
Daevius
PS: Java style commenting? Whenever I watch the source code of something I always first clear out those comments, as they look messy to me and take to much space to see in one view what it all does...but yeah, all preferance ;)
That's because you're a silly goose :tongue:
Check out this: it's the documentation generated from sourcefiles of a work in progres, specifically the 'Master' class docs, you can see there the clean sourcecode (without the comments) with links to the actual comments! Since I used JAVA style comments there the documentation can automatically be generated and searched trough, much easier than when you'd have to do it yourself :icon6:
Re: What about your brains?
Aye, that looks better :).
I don't like the documentation thingy too ^^, (just like the ones they have on pear.php.net), they just look messy and just by looking at the code you understand it quicker. Would be nice if you just hide the comment except when you click it ;).
But as said, if you use a style (recommended) use it consistently, comments might add nothing to the program at first sight, it helps you later on ;).
Anyways, this is a piece of my C++ code calling Lua:
Code:
#include <iostream>
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
using namespace std;
int main()
{
lua_State *L;
L = lua_open();
luaL_openlibs(L);
if (luaL_loadfile(L, "script.lua"))
{
fprintf(stderr, "Script error\n");
return 1;
}
if (lua_pcall(L, 0, LUA_MULTRET, 0))
{
fprintf(stdout, "Script error\n");
return 1;
}
lua_pop(L, 1);
lua_close(L);
return 0;
}