Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 515 516 [517] 518 519 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 908165 times)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #7740 on: September 04, 2015, 12:35:02 pm »

I don't like writing what code does in comments. That's what the code is for. If I want to know what a function does and can't tell by it's name, that's what the unit tests are for. If I can't understand either of those, it's very unlikely a comment would of helped clarify things any better.

A "Why I did this" comment can be useful, especially when doing browser dev. You know, "Works around bug in IE8 where this outdated browser insists on remaining a pile of horse plop", that kinda thing (Bloody enterprise clients, some of them still insist on supporting IE6).
« Last Edit: September 04, 2015, 12:41:19 pm by MorleyDev »
Logged

Ghills

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7741 on: September 04, 2015, 11:06:43 pm »

same here, no comments

if the code smells so much you're tempted to comment it, move it to it's own method until it became clear and name the method as you would explain the operation in the comment.



above all thing, all developers should read code complete.

Code should be the 'what' sure - as in, 'what does this do' - but comments are needed for 'why did we do this/do this this way', 'how and where this function is used', 'when this was added', 'who added it', etc.  Only one of the fundamental questions can be answered by code, regardless of how clear the code is.
Logged
I AM POINTY DEATH INCARNATE
Ye know, being an usurper overseer gone mad with power isn't too bad. It's honestly not that different from being a normal overseer.
To summarize:
They do an epic face. If that fails, they beat said object to death with their beard.

Ghills

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7742 on: September 04, 2015, 11:08:34 pm »

I don't like writing what code does in comments. That's what the code is for. If I want to know what a function does and can't tell by it's name, that's what the unit tests are for. If I can't understand either of those, it's very unlikely a comment would of helped clarify things any better.

A "Why I did this" comment can be useful, especially when doing browser dev. You know, "Works around bug in IE8 where this outdated browser insists on remaining a pile of horse plop", that kinda thing (Bloody enterprise clients, some of them still insist on supporting IE6).

'What this does' comments can be useful as a brief refresher when coming back to a project or introducing a new coworker to the code.  They save a lot of time vs reading code that was written by someone else 6 months ago and has left the team since.
Logged
I AM POINTY DEATH INCARNATE
Ye know, being an usurper overseer gone mad with power isn't too bad. It's honestly not that different from being a normal overseer.
To summarize:
They do an epic face. If that fails, they beat said object to death with their beard.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7743 on: September 05, 2015, 01:06:02 am »

same here, no comments

if the code smells so much you're tempted to comment it, move it to it's own method until it became clear and name the method as you would explain the operation in the comment.



above all thing, all developers should read code complete.

Code should be the 'what' sure - as in, 'what does this do' - but comments are needed for 'why did we do this/do this this way', 'how and where this function is used', 'when this was added', 'who added it', etc.  Only one of the fundamental questions can be answered by code, regardless of how clear the code is.

Minor disagreement. I think 'who added it' and 'when this was added' shouldn't be handled by comments but rather by version control software, like git.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7744 on: September 05, 2015, 02:55:47 am »

but comments are needed for 'why did we do this/do this this way', 'how and where this function is used'
Especially the second one suffers from severe code rot, which should be provided by editor/IDE features and documentation, not by comments.
Logged
Taste my Paci-Fist

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7745 on: September 05, 2015, 05:41:47 am »

but comments are needed for 'why did we do this/do this this way', 'how and where this function is used'
Especially the second one suffers from severe code rot, which should be provided by editor/IDE features and documentation, not by comments.

however, if it is part of a library, document the heck out of it. throw exception early for any wrong input, document the exception, and put a relevant message in the exception (sorry I'm just a lot salty about our current platform)
Logged

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7746 on: September 05, 2015, 05:26:57 pm »

so, I learned LUA today and having a blast programming missile guidance system for a videogame (From the Depths)

have a look!

probabilistic guidance: shoot a cloud of missiles around the target possible future position and let the target slam into one of them -  https://www.youtube.com/watch?v=0eTGJraqANw

javelin guidance: cilmb to 100mt above the target and tries to hit it from the vertical to avoid the citadel armor - https://www.youtube.com/watch?v=BbYnRUo40EY

Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7747 on: September 05, 2015, 07:06:35 pm »

Lua's a name, not an acronym!

Anyway, yeah, Lua's really good for scripting stuff. I made a homing missile system in Super Metroid using lua-script memory hacking, but it's simple as hell: it sets the missile's acceleration vector (a byte in the projectile's memory that sets whether it's moving up, down, left, right or some diagonal, there's some overlap in there) based on the position of the nearest enemy (going diagonal unless the enemy is directly in a cardinal direction). It works surprisingly well. Interestingly enough, each projectile has a different acceleration speed; missiles are the most reliable at homing since they accelerate fairly quickly (but not too quickly!), super missiles go too fast to be reliable (they tend to overshoot) and beams can't really turn around.

https://gfycat.com/DentalBlackLadybug

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7748 on: September 05, 2015, 08:57:57 pm »

Though I'm still not convinced that comments are totally bad, I do notice myself using them less often as I develop my skills more.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Calidovi

  • Bay Watcher
  • agnus dei
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7749 on: September 05, 2015, 09:04:33 pm »

Though I'm still not convinced that comments are totally bad, I do notice myself using them less often as I develop my skills more.

I spam comments because I have a horrible memory and am poor at recognizing the purpose of most of the functions I put in.
Logged






MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #7750 on: September 06, 2015, 04:12:12 am »

Code should be the 'what' sure - as in, 'what does this do' - but comments are needed for 'why did we do this/do this this way', 'how and where this function is used', 'when this was added', 'who added it', etc.  Only one of the fundamental questions can be answered by code, regardless of how clear the code is.

I'm of the mind that how and where are better addressed via Unit Tests (demonstrating the how) and "Find Usages" (to find the where), and a good code structure that breaks things down into collected set of namespaces that naturally build upon each other (to indicate the where it goes, the intent behind those namespaces may need to go in comments or documentation though).

I do tend to write more thorough comments when not also writing unit tests and specification tests and such, but in my mind that's me trying to compensate for the lack of having time to do it the 'proper way' :)

And yeah, When and Who are surely source control concerns? :) git blame and svn blame. Kinda dislike the names of those (you aren't blaming anyone! That word has negative connotations! Negative!), but they are useful when you need to know who did a thing and when. Back and before the VSS legacy project days, "Who and When" comments had more purpose though, and I've had to crack open a legacy project or two in my time.

Which is how I view commenting: It's a fallback for when your tools and process are currently limiting your capacity to do things the 'proper way' due to time or technology constraints. Deadlines gonna deadline and managements gonna management, and some tools just don't allow you to encode things effectively in the code or the tool.
« Last Edit: September 06, 2015, 04:44:45 am by MorleyDev »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7751 on: September 06, 2015, 04:33:32 am »

Though I'm still not convinced that comments are totally bad, I do notice myself using them less often as I develop my skills more.
comments are really important imo, a big thing is just understanding when to comment and when not to comment.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7752 on: September 06, 2015, 04:31:38 pm »

Though I'm still not convinced that comments are totally bad, I do notice myself using them less often as I develop my skills more.
comments are really important imo, a big thing is just understanding when to comment and when not to comment.
Indeed, a factor that involves a fair bit more than just what you are doing in any sort of real project, but also factors in things like how many people are expected to interact with that particular bit in the lifetime of your code, their expected skill levels, and so forth.

I'm certainly going to do more comments on an open source project with 300+ contributors like Cataclysm: DDA than I am on a project only for my own personal use.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7753 on: September 06, 2015, 04:44:39 pm »

Though I'm still not convinced that comments are totally bad, I do notice myself using them less often as I develop my skills more.
comments are really important imo, a big thing is just understanding when to comment and when not to comment.
It's a good reason to use full English names for functions and variables. For example a function like DistanceSquared(vector, vector) really doesn't need a comment, but if you were lazy and called it "d2" it would need a comment. But someone who saw "d2(a,b)" in your code somewhere might have to backtrack to the function declaration to read that comment, which kinda sucks.

With auto-complete in modern IDEs there's basically no excuse not to use fully descriptive names everywhere. It just makes the code easier to read and needs less comments.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7754 on: September 06, 2015, 07:57:07 pm »

That is exactly why I hate working with old Fortran code.  Probably new Fortran code too for that matter, or any scientific code.  I guess I can understand that it's annoying to write "first_derivative_of_x(i, j)" a hundred times, but at the same time I really hate having to scan a source file for a comment to explain what the variable "wsct0(i, j)" means.  If there's a comment at all.
Logged
Through pain, I find wisdom.
Pages: 1 ... 515 516 [517] 518 519 ... 796