• Coding Tricks
    122 replies, posted
Post the weird things you always do when writing your code. As for me: When a C++ program is to simple I make a function for every little thing as a challenge. Everything has to be tabbed exactly 5 spaces for set of {}'s. It pains me to see it otherwise.
[QUOTE=ryan1271;20407420]Post the weird things you always do when writing your code. As for me: When a C++ program is to simple I make a function for every little thing as a challenge. [/quote] Regardless of simplicity, you should make a function for every block of code that does a single, concrete task. [quote] Everything has to be tabbed exactly 5 spaces for set of {}'s. It pains me to see it otherwise.[/QUOTE] Just use tabs and mess with your IDE options to display tabs as 5 spaces.
-snip- :3:
I always tend to use calculus to do every thing. I figure, anything can be done in calculus. Here's how I output Text in console now: [cpp] void Output(std::string Text) { bool Calculus = true; if(Calculus) { std::cout<<Text; } } [/cpp]
1.) Use tab char's [TABS MUST = 4 SPACES >:(] 2.) Code blocks must be like this:[code] <function / if / loop> { <----- ... } [/code] 3.) Avoid helper libraries :x
[QUOTE=xAustechx;20408041]I always tend to use calculus to do every thing. I figure, anything can be done in calculus. Here's how I output Text in console now: [cpp] void Output(std::string Text) { bool Calculus = true; if(Calculus) { std::cout<<Text; } } [/cpp][/QUOTE] your code is useable but very ugree, you should consider skinning it or using crazy eddies GUI, myGUI, QuickGUI, ButtonGUI, perro GUI, RocketGUI, don't get offended if im missing something.
[QUOTE=efeX;20408109]your code is useable but very ugree, you should consider skinning it or using crazy eddies GUI, myGUI, QuickGUI, ButtonGUI, perro GUI, RocketGUI, don't get offended if im missing something.[/QUOTE] What if I added more calculus?
[QUOTE=ryan1271;20407420] Everything has to be tabbed exactly 5 spaces for set of {}'s. It pains me to see it otherwise.[/QUOTE] Have fun reading 99% of code in the world. :v: And have fun modifying it and screwing it up with your 5 spaces.
[QUOTE=PvtCupcakes;20408195]Have fun reading 99% of code in the world. :v: And have fun modifying it and screwing it up with your 5 spaces.[/QUOTE] Maybe if he used calculus it wouldn't be as bad.
[QUOTE=xAustechx;20408613]Maybe if he used calculus it wouldn't be as bad.[/QUOTE] [img]http://i50.tinypic.com/k0lvyq.jpg[/img] [highlight](User was banned for this post ("Image macro/flaming" - SteveUK))[/highlight]
1) Must Tab. Properly. 2) Conditionals cannot have a space after or before the parenthesis: if(boolean) {} 3) Function parameters must have a space after and before the parenthesis: foo( bar ); 4) Blocking must be: [cpp] void foo( int bar ) { std::cout << bar << '\n'; } if(boolean) { foo( bar ); } [/cpp]
OH! My conditionals MUST be like this: if( CONDITION ) { ... }
Because you code in java ????
[QUOTE=TehBigA;20408853]OH! My conditionals MUST be like this: if( CONDITION ) { ... }[/QUOTE] what. no. stobbit.
I do [code] void foo(int bar) { // two space tabs and one space after comments } [/code]
I spend way too much time trying to name things perfectly. In theory, it's a good thing to try and come up with apt names, but I'm not very good at naming so I end up rolling around in my bed racking my brain for that perfect name. Then an hour later it's description changes slightly and I spend 10 minutes replacing all the instances with a new name. [editline]08:51PM[/editline] Oh, and operators always come right after the first variable and then there's a space before the next, like so: x- y Also, I used to be obsessive about parenthesis having spaces between them: (x- (a+ b)) [I]bad[/I] ( x- (a+ b) ) [I]good[/I]
I hate having this [code]void Function() { }[/code] So I do this instead for everything. [code]void Function() { }[/code] I also hate having spaces between parenthesis unless seperating arguments in a function call.
[QUOTE=lemming77;20409358]I hate having this [code]void Function() { }[/code] So I do this instead for everything. [code]void Function() { }[/code] I also hate having spaces between parenthesis unless seperating arguments in a function call.[/QUOTE] I like the way you hate better. Seems easier just looking and being able to see where the start and end of a statement is.
Well it's not like the function (in this case) is going to start anywhere before the declaration. :P Just makes it all more compact, which I'm more comfortable working with.
[QUOTE=lemming77;20409358]I hate having this [code]void Function() { }[/code] So I do this instead for everything. [code]void Function() { }[/code] I also hate having spaces between parenthesis unless seperating arguments in a function call.[/QUOTE] Same way. For both.
[code] function a(int arg1, string arg2) { // indented with tabs, four spaces width if(condition) return; // no braces, next line is tabbed if it's just one line stuff if(longer & condition) { return again; } else { return never; } } [/code] Not sure how standard\substandard this is, but it works for me. I'm ridiculously picky about TAB vs Spaces though, I cannot stand spaces. The fact that it takes up an extra three bytes per set of four spaces is minor enough, but just the way the selection doesn't jump smoothly through the indents. Plus, using spaces is just an excuse to start having non-uniform indentation, like half-width indents for public: or private: in classes, for example, or having tab-and-a-half width for comments and things. It just seems unnecessary and useless when you could just as easily have a tab character display as four columns wide, use that, have a smaller space taken up per file and require less formatting maintenance to get the files looking the same. That's my take on why tabs are better than spaces though... anyone here using spaces care to explain your reasoning?
Spaces are also a bitch to backspace compared to tabs.
I'm an extra step of anal past the brace wars, I have to have the brace on the same line as the conditional, and [i]it can't have a space between the close paren and the open brace[/i]. Oh, and tabs for me. [cpp]if(calculus){ // TODO: Derive an algorithm } [/cpp]
I can live with many coding conventions. I'm quite anal with const-correctness though.
[QUOTE=ZeekyHBomb;20412274]I can live with many coding conventions. I'm quite anal with const-correctness though.[/QUOTE] Same. It's not like every convention fits every language. Especially when it comes to naming conventions and stuff like that; I use a lot of different programming languages and I use different conventions in all of them.
must optimize for loops [CODE] for i=1,40,4 do function(i) function(i+1) function(i+2) function(i+3) end [/CODE] is equal to [CODE] for i=1,40 do function(i) end [/CODE]
What? Isn't the lower one faster? In the upper loop, it has to create temporary objects and use an addition (binary function), instead of just incrementation (unary function).
I too write my code like so: [cpp] if( Blergh ) { }[/cpp] I think it might have something to do with the fact that I started coding in Lua and AutoIt, where they use "Then" on the same line as the statement instead of curly brackets to encapsulate code blocks.
-I never use do-while loops, I find them redundant. While and for are all I've ever needed. -I always have spaces for things in brackets ( like this ), and spaces in arithmetic + statements = like this. -Braces always on a new line. -If I have a statement following a closing brace, I put an empty line in between the two. -I keep an empty line above and below if-statement and loop bodies. Exception to an empty line above the body is when the previous line has an opening brace. I guess this is my weirdest tick. -Tabs ftw. -camelCase for variable and function names, start with a capital letter for classes.
[QUOTE=ZeekyHBomb;20412932]What? Isn't the lower one faster? In the upper loop, it has to create temporary objects and use an addition (binary function), instead of just incrementation (unary function).[/QUOTE] The lower one will be faster because the compiler will do the same job as above, except better than every coder can. It's called loop unrolling. You only do it manually if your compiler sucks at it, after rigorous profiling.
Sorry, you need to Log In to post a reply to this thread.