Re: What about your brains?
Can't say I have ever felt this way about coding normally I just turn to google for answers to my problem, if I can't find them through google then someone usually has posted the same thread along way back so I search here if in doubt I just create a thread and normally Daevius is the first to answer lulz.
Last time I posted here, it was a problem with database management in Java, it was something simple through.
Re: What about your brains?
since its my work and afterworks i do around 3/4 hours java coding to relax
no ! :)
Re: What about your brains?
I see what you mean. Thats why I like debuggers :)
Since C and PHP display error messages, it's usually easy to fix the error. However Javascript just stops working...that is VERY nasty to work with. One character wrong and the entire script you wrote is useless. Then by placing alert calls and out-commenting the code, you 'lock in' the error...and then you notice that you forgot a dot or a bracket...
That is very frustrating.
But since C and PHP have proper error displaying (for C its build-in in my IDE for most common errors, however some errors (like accidently accessing protected memory for instance)) just need to be 'locked in'. A debugger for that is quite nice though :)
Once I get frustrated or cannot find the answer quickly enough I drop it and start playing a game :(, since I play bad when I'm frustrated I get even more frustrated lol!
But once you solved a problem, it makes you feel much better :), compensates the frustration and keeps you happy for a new problem ^^
Stopping when you're frustrated is not really the way to go though, as next time you don't know where you ended...or you forget the complete project ^^.
For me a no, as my problems are usually solved quickly...else I just stop programming ;)
Re: What about your brains?
Quote:
Originally Posted by
Daevius
But once you solved a problem, it makes you feel much better :), compensates the frustration and keeps you happy for a new problem ^^
'zactly! :smile:
JS isn't that hard if you have something like firefox's error console to show you where the problem is - works best if you're modifying an existing script of course; if you're writing something from scratch and have to write a page of stuff before any of it will do anything, then I guess it can get hairy... I'm usually pretty lucky with that though :thumb:
The most annoying thing with web langs is the need to constantly compensate for browser failings and differences - at least with app langs (I assume) you pretty much know how it's going to look and behave on almost any PC (unless you're doing something with ridiculous dependencies like the .NET framework sturf)? :huh:
Re: What about your brains?
Quote:
Originally Posted by
evill33t
since its my work and afterworks i do around 3/4 hours java coding to relax
no ! :)
Same, but with PHP afterwards :icon6:
Note, if you have 60 declared variables all in your current scope the problem is not your brain, it's your crappy code. Learn to abstract code, place them in new classes whenever you require them, generalise, keep your functions small and to the point.
All my functions fit on my screen at 1280x1024, including their comments. If I ever tend to write one that doesn't fit I start putting parts of it in other objects / methods, or sometimes just delete the whole thing and redo from start. Especially when my brain starts to hurt a bit when looking at something I delete the code, get a cup of tea and write it again elegantly :icon6:
Re: What about your brains?
Var goes here and var goes there.
In PHP I mostly stick to arrays, since they're a lot easier(imo) to use, and you don't have to
remember all the names. Just print_r() if you can't remember what is where and yer done. ;]
[Fd]
Re: What about your brains?
You can easily work on even 1000 variables with well prepeared UML diagram.
Re: What about your brains?
The coding I do is pretty simple as I'm not a fantastic fan-dabby-dozy coder. I just make small, simple things in school like a Dice Game or a rainfall calculator.
Re: What about your brains?
Quote:
Originally Posted by
DanseMacabre
You can easily work on even 1000 variables with well prepeared UML diagram.
with a well prepared uml diagram you wont have 1000 variables ;) at least not global or in one method
Re: What about your brains?
Quote:
Originally Posted by
FragFrog
Note, if you have 60 declared variables all in your current scope the problem is not your brain, it's your crappy code. Learn to abstract code, place them in new classes whenever you require them, generalise, keep your functions small and to the point.
I was going to say something along those lines.
Practice good coding style, including but not limited to functions of proper size like FF said, good naming conventions and the like. Even such irrelevant minor details as indentation and empty lines, not to mention commenting your own code, are things that greatly improve readability and hence make blowing of your brain less likely. :)
Re: What about your brains?
Jesus what's with all the variables I pointed them just because of example.
Re: What about your brains?
Quote:
Originally Posted by
Negata
Even such irrelevant minor details as indentation and empty lines, not to mention commenting your own code, are things that greatly improve readability and hence make blowing of your brain less likely. :)
Aye, very true. Everyone has it's own programming style, but if you're going to publish your code, the best way is to use the fishtail method. Like this:
Code:
if (...)
{
while (...)
{
// comment!
}
switch (...)
{
case '...':
{
// aye
break;
}
}
}
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 :)
And yes: OOP reduces the ammount of variables...alot. But use it sparingly, not for every variable ^^
Re: What about your brains?
Sometimes. If I start a really big project, randomly stop coding for it, and then try to resume it later, it can be a headache. However, I never run into issues with variables due to the beloved "option explicit" in VB and because of how I name them.
Re: What about your brains?
Quote:
Originally Posted by
Daevius
Aye, very true. Everyone has it's own programming style, but if you're going to publish your code, the best way is to use the fishtail method.
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. But it really doesn't matter what style you adopt, as long as you do it consistently in your entire project :smile:
Add some decent other guidelines and you get code that never gives you an headache:
PHP Code:
class Someclass {
/**
* If $foo equals $bar we do something, else we do
* something else.
*
* @param $foo String Could be a bar.
* @param $bar String Could equal foo.
**/
public function someFunction ($foo, $bar) {
if ($foo === $bar)
$this -> doSomething();
else
self::doSomethingElse();
}
/**
* Do a specific something, ie, echo 'Hello world'!
**/
private function doSomething () {
echo 'Hello world';
}
/**
* Echo a farewell message to the world in general.
**/
private static function doSomethingElse () {
echo 'Goodbye cruel world!';
}
}
Code like this is used most troughout the company I work for; lot of specifics in it as well like putting a space between functionname and argument, using JAVA style comments, putting blanks around operators and keeping 2 newlines between functions. You'll also notice classnames start with a capital letter, members with a normal one, as do variables, and camelCase is used throughout.
Usually we also define return values, author and exceptions thrown in the comments, but all of these returned void and I don't want to bore you all with more laps of code :icon6:
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;
}