• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
irreversible

Share your wisdom! Sage thoughts related to programming you've discovered over the years

43 posts in this topic


 

"Always document your code."

 

- alnite, 2013

 
 
If you don't understand why, you will sooner or later.

 

 
Code documentation is overrated and violates DRY. If your code needs documentation, it's not simplified enough. ;)
 

 


Code shouldn't need documentation in order to make what the code does understood. Code very often does need documentation of why a particular approach was taken instead of other, competing approaches.

 

Keep in mind, I'm not talking about commenting code, which is a whole different thing.

 

If I have to read code line by line to know what it does, then I know I have failed in writing a reusable code.

0

Share this post


Link to post
Share on other sites

"If you're going to be writing cryptographic code, and you're not sure what you're doing,

just put the keyboard away and ask someone qualified to write it for you. For all our sakes."

 

                                                                                                 - Bacterius, 2013

 

Or, really, the more general statement - if your code is going to be used in situations where it failing could have very real consequences, don't write the code if you cannot assume said consequences. Seriously, the Dunning-Kruger effect is omnipresent in the field of programming, and not taking it into account is a recipe for disaster. See the recent utter failure of the Mega file sharing website's launch - the developer had no clue what he was doing, and the result is painfully obvious and predictable.

I'm writing cryptographic code and I'm not 100% sure what I'm doing. Should be interesting LOL
0

Share this post


Link to post
Share on other sites

[quote name='alnite' timestamp='1358908519' post='5024569']
If I have to read code line by line to know what it does, then I know I have failed in writing a reusable code.
[/quote]

 

Agreed. What code does is different than how code does it smile.png

0

Share this post


Link to post
Share on other sites

Use descriptive variable names. Seriously, this is one thing I don't understand. Probably 3/4s of my job is reading code and 1/4 writing; prioritize making code easy to read.

0

Share this post


Link to post
Share on other sites

Use descriptive variable names. Seriously, this is one thing I don't understand. Probably 3/4s of my job is reading code and 1/4 writing; prioritize making code easy to read.

QFT.

 

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.

Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. sad.png

0

Share this post


Link to post
Share on other sites

Use descriptive variable names. Seriously, this is one thing I don't understand. Probably 3/4s of my job is reading code and 1/4 writing; prioritize making code easy to read.

GODS YES.  QFT again!

 

The codebase I work on currently (dayjob-wise) is so utterly illegible thanks to shortened function names and variables that I spend 5x longer than I should have to referring back to headers for commented struct fields.  It's a joy afterwards to dive back into my own project and actually read my code instead of translate it.

 

I can't add anything new, all my favorites and "amen" moments are already in the list.

0

Share this post


Link to post
Share on other sites

Use descriptive variable names. Seriously, this is one thing I don't understand. Probably 3/4s of my job is reading code and 1/4 writing; prioritize making code easy to read.

QFT.

 

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.

Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. sad.png

 

Looks like he was texting the compiler...
0

Share this post


Link to post
Share on other sites

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 

What the—

 

I do sometimes use abbreviations, but only those that are pretty much well-known in programming anyway (like ptr for pointer or len for length). Otherwise I don't use abbreviations. I still aim for short names, though (just because you have a huge monitor doesn't mean you have to make function names longer, it eventually becomes too hard to read just because it's too long). I noticed that a lot of long function names involve either them being too overly descriptive (whatever happened to context?) or are functions that are doing multiple tasks at the same time (which usually means there's a problem in the design).

 

If your "long" function name is something like draw_level_background, that's probably OK - concise but makes very clear what it does. If your function name is something along the lines of this (and I've seen some APIs do that) then we have problems =P

Edited by Sik_the_hedgehog
0

Share this post


Link to post
Share on other sites

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 


 

If your "long" function name is something like draw_level_background, that's probably OK - concise but makes very clear what it does. If your function name is something along the lines of this (and I've seen some APIs do that) then we have problems =P

 

I'm beginning to think that I'm actually not a bad code writer.

0

Share this post


Link to post
Share on other sites

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 

 

This. Never looked back.

0

Share this post


Link to post
Share on other sites

This has come up a couple times very recently when helping others fix their code, so I'm going to say it here.

 

If your API functions return error codes, check them.

 

and for the exception-related corollary:

 

putting "throws exception" everywhere in your code is like throwing a psychotic mass murderer in jail and forgetting to lock the cell.

0

Share this post


Link to post
Share on other sites

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 

 

This. Never looked back.

That only solves the writing code problem, not the reading code problem.

0

Share this post


Link to post
Share on other sites

 

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 

 

This. Never looked back.

That only solves the writing code problem, not the reading code problem.

By that description it solves the problem, doesn't it?

0

Share this post


Link to post
Share on other sites

 

 

Have previously worked on a code base where the original programmer didn't like typing so everything is named using 3 letter abbreviations strung together.
Want to calculate the distance between two points? Call the ClcDstBtw2Pts method! Need to know the value of the taxable amount on account balance? It's in the txAmtAccBal variable. And that's not a typo, the 'a' in tax was felt to be superfluous. 

 

This. Never looked back.

That only solves the writing code problem, not the reading code problem.

By that description it solves the problem, doesn't it?

 

It requires rewriting the code to achieve that. Good luck doing that in a huge project... You're guaranteed you will break something, and you're guaranteed you will upset everybody else working with you (and especially your boss).

0

Share this post


Link to post
Share on other sites

I'm not trying to endorse the software (though I personally find it invaluable) but 1) refactoring really is much less of a pain than you would think with VAX (which, at the end of the day, might be a better option if you're stuck with a truly cryptic codebase) and 2) I was not implying it makes code easier to read, but rather that if you're going to be abusing long names in the code, always use as much itellisense/autocomplete functionality to start with. That's what it's there for. The prod wasn't at ChaosEngine, but rather the person who wrote the code.

0

Share this post


Link to post
Share on other sites

My grandfather once said

 

"The time taken to think something through before doing it is often well spent."
                                                                                   -Jørgen Jørgensen

I've yet to prove him wrong.

I never come up with anything clever to say. On purpose, at least. smile.png

Aside from perhaps...

 

    "Always listen to Bregma." biggrin.png

Edited by SuperVGA
0

Share this post


Link to post
Share on other sites

I'm not trying to endorse the software (though I personally find it invaluable) but 1) refactoring really is much less of a pain than you would think with VAX (which, at the end of the day, might be a better option if you're stuck with a truly cryptic codebase) and 2) I was not implying it makes code easier to read, but rather that if you're going to be abusing long names in the code, always use as much itellisense/autocomplete functionality to start with. That's what it's there for. The prod wasn't at ChaosEngine, but rather the person who wrote the code.

 

I didn't take it as a dig at me, and I'm familiar with VAX; it's a great tool.

 

But in this case, the goal was to replace the legacy C++ code base with new functionality written in C# (with unit tests, yay!) so any refactoring effort on the C++ ultimately wouldn't have been worth it.

0

Share this post


Link to post
Share on other sites

I'm just going to throw this out there because I've suffered a lot from it:

Don't copy and paste code!

a) Common and large enough code should be in a function

and 

b) Copy-pasting will lead you to copy your mistakes, cause you to forget to rename variables and generally be bad for you

 

It's 3am here, and I just realized that the reason my code crashes at runtime is two lines that I copy-pasted but had forgotten to rename one of the parameters accordingly. F*ck me.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0