• Commenting
    60 replies, posted
[QUOTE=Loli;16518900]/** @file COSLayerWin32.h **/ Don't use this. [b]To optimise your code us[/b] // //@file COSLayerWin32.h //[/QUOTE] wat?
Thanks loli I've changed all my comments and now my code runs 3.7% faster.
I usually do a lot of commenting in small scripts and add a way to view the source, so if someone wants to know how my script works they're more than welcome. This is also hugely necessary because of my tendency to name variables 'asd' and 'asdaf', not that the comments always help though: [code]$argh = 0; // define argh $lol1 = $array2 - 1; // very unreliable duplicate counting, this is when you have unlocked all unlocks once $euroshoppersperzieboontjes += $array2; // and this is if you haven't, the name of this variable is hard to explain and involves inside jokes if(!isset($lol2)) { // this is a rediculous way to do this.. $lol2 = $lol1; }else{ $lol2 += $lol1; } // ..but it works $wut = count($asd[0]) - 1; // this is for a something in line 46 $argh -= 1; // thankfully I already don't remember this [/code] These are all copy and pastes of [url="croil.net/items.php?source=ja"]the same script[/url] (scroll down).
[QUOTE=Loli;16518900]/** @file COSLayerWin32.h **/ Don't use this. To optimise your code us // //@file COSLayerWin32.h //[/QUOTE] ..... First of all.. You gave two horrible examples. In the first one, no one uses a multi line comment for one line anyway... so I don't think there is any point in telling people not too.. And in the 2nd one, you wouldn't use three comment lines when trying to comment out three lines.. You'd only need one.
[QUOTE=SolidusBlack;16525697]..... First of all.. You gave two horrible examples. In the first one, no one uses a multi line comment for one line anyway... so I don't think there is any point in telling people not too.. And in the 2nd one, you wouldn't use three comment lines when trying to comment out three lines.. You'd only need one.[/QUOTE] It was an example... But, yeah I can see where you are coming from!
most of my variables/classes/function names/parameters are all self-explanatory, i don't need to comment much. stuff like this: [code] HDC deviceContext; // the device context [/code] is just plain retarded.
Plus I use comments to disable pieces of code.
[QUOTE=compwhizii;16531229]Plus I use comments to disable pieces of code.[/QUOTE] that's pretty much all i use them for.
[QUOTE=compwhizii;16531229]Plus I use comments to disable pieces of code.[/QUOTE] Much more efficient than just deleting pieces of code. :v:
I use single line comments when something gets repetitive. comments that span multiple lines... Only use them to remind me of certain stuff. For example, if you're making a game, you should keep something like this: [CODE] /*Character C3 Stats (before scene 5): * *HP: 100 *Strenght: 86 *Stamina: 45 * */ [/CODE]
[QUOTE=compwhizii;16531229]Plus I use comments to disable pieces of code.[/QUOTE] If you want to "comment out" a bunch of lines of code, use "#if 0" and "#endif" instead. Unlike /* */ comments, #if is nestable, and you can put replacement troubleshooting code in an #else and switch between that and the original code just by changing the #if parameter between 0 and 1. (This assumes you're using a language that has a preprocessor, e.g. C/C++. I do a lot of Java these days and often wish it had a preprocessor just for this reason.)
I find commenting to be really helpful.
[QUOTE=Wyzard;16532681]If you want to "comment out" a bunch of lines of code, use "#if 0" and "#endif" instead. Unlike /* */ comments, #if is nestable, and you can put replacement troubleshooting code in an #else and switch between that and the original code just by changing the #if parameter between 0 and 1. (This assumes you're using a language that has a preprocessor, e.g. C/C++. I do a lot of Java these days and often wish it had a preprocessor just for this reason.)[/QUOTE] That could be confusing if you use an IDE.
My rule with commenting is... if you are the one that is going to be changing your code and using it then you don't have to comment if you can read it back and completely understand it. Especially if you have good naming conventions. However, if you think at any time that someone else is going to be using your code or modifying it or looking at it at all then you should comment as much as possible.
[QUOTE=Squad;16534825]My rule with commenting is... if you are the one that is going to be changing your code and using it then you don't have to comment if you can read it back and completely understand it. Especially if you have good naming conventions. However, if you think at any time that someone else is going to be using your code or modifying it or looking at it at all then you should comment as much as possible.[/QUOTE] Same for me here.
[QUOTE=Squad;16534825]My rule with commenting is... if you are the one that is going to be changing your code and using it then you don't have to comment if you can read it back and completely understand it. Especially if you have good naming conventions. However, if you think at any time that someone else is going to be using your code or modifying it or looking at it at all then you should comment as much as possible.[/QUOTE] if you have good naming conventions, you don't have to comment as much as possible...
[QUOTE=Ortzinator;16534127]That could be confusing if you use an IDE.[/QUOTE] Decent IDEs ( Visual Studio ) will parse these.
[QUOTE=Ortzinator;16534127]That could be confusing if you use an IDE.[/QUOTE] Not really, no, unless your IDE/theme sucks ass.
I don't normally comment my code (I find it unbearable most of the time), but if I'm working on a group project I comment parts that help others understand. Most of my code is easily understandable without commenting either way, so I don't see the point for me.
[QUOTE=blankthemuffin;16535805]Decent IDEs ( Visual Studio ) will parse these.[/QUOTE] Ok, didn't know this.
I usually use comments to tell me what the hell all my variables and functions represent and do because I have an uncanny knack for naming everything after my pets or favorite superheroes. Also after @interface/implementation - @end and restate the name of the class for the betterment of understanding and remembering everything I do when I'm forced to work in Objective C on a mac or whatever.
[QUOTE=moomooplatt;16544736]naming everything after my pets or favorite superheroes.[/QUOTE] Coding done wrong.
[QUOTE=compwhizii;16544780]Coding done wrong.[/QUOTE] Obviously if I'm writing an entire engine, I'll use appropriate names, but I generally just code simple useful tools when I need them. They end up having very few classes, and end up saving me time. If I need to edit them for a slightly different implementation, I need to remember what Gizmo is in a 100 line program.
[QUOTE=moomooplatt;16544736]I usually use comments to tell me what the hell all my variables and functions represent and do because I have an uncanny knack for naming everything after my pets or favorite superheroes. Also after @interface/implementation - @end and restate the name of the class for the betterment of understanding and remembering everything I do when I'm forced to work in Objective C on a mac or whatever.[/QUOTE] wat?
[QUOTE=nullsquared;16545046]wat?[/QUOTE] my thoughts exactly
[QUOTE=moomooplatt;16544736]I usually use comments to tell me what the hell all my variables and functions represent and do because I have an uncanny knack for naming everything after my pets or favorite superheroes. [/QUOTE] Consider an occupation in veterinary medicine or comic books.
[QUOTE=moomooplatt;16544827]Obviously if I'm writing an entire engine, I'll use appropriate names, but I generally just code simple useful tools when I need them. They end up having very few classes, and end up saving me time. If I need to edit them for a slightly different implementation, I need to remember what Gizmo is in a 100 line program[/QUOTE] That's not really a rationale for naming it "Gizmo" in the first place, though.
I almost never use comments (I know this is a bad thing, but I can't help myself), but OP is seriously overdoing it.
[QUOTE=moomooplatt;16544827]Obviously if I'm writing an entire engine, I'll use appropriate names, but I generally just code simple useful tools when I need them. They end up having very few classes, and end up saving me time. If I need to edit them for a slightly different implementation, I need to remember what Gizmo is in a 100 line program.[/QUOTE] Writing comments like this will take you longer than like the half a second it wll take to give things proper names
[QUOTE=efeX;16535238]if you have good naming conventions, you don't have to comment as much as possible...[/QUOTE] Really depends, not everything relies on naming conventions. I don't care if you disagree, but just because I know the name of something I may not know someones exact reasoning behind doing something the way they did it. I would rather read a short comment to understand something, then try to go throughout the entire program trying to figure out what the coded does.
Sorry, you need to Log In to post a reply to this thread.