• 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
Tutorial Doctor

Ugh! Your shorthand is too short!

43 posts in this topic

One of the most annoying things I keep seeing is people who write shorthand code with variables like:

i = true

Where "i" means "initialize" or some miscellaneous other word that starts with an "i." 

 

How will you go back later and debug when the code has reached 1,000,000 lines and you forgot what "i" does?

 

Better yet, even 1,000 lines would throw me for a loop (pun intended). 

 

I mean, C++ code is already cryptic enough, why the extra brevity?

 

Sometimes I truly think people initially write the full names in the code, and then go back and make things cryptic on purpose just to scare away code thieves. In that case I understand, but is the stereotype really true that programmers are just lazy?

 

There is a way to be brief yet descriptive without feeling like you are monologuing in your code. I understand that we can sacrifice a little human readability (according to human language standards) for the sake of "getting it done" but really....

 

Something like:

init = true

would be better, but even then....

 

Anyone else know what I'm talking about (I am a beginner)?

Edited by Tutorial Doctor
1

Share this post


Link to post
Share on other sites

The more annoying thing aboug one-letter variables is about highlighting or finding them (pray you do not have to refactor such code), not so much about understanding what they mean (if the programmer is only somewhat sensible, the purpose of one-letter names is usually still obvious).

 

But once you find out that your editor lets you conveniently highlight all occurrences of greater-than-N substrings (usually N=3) you start shouting at people who use one-letter variables because it doesn't work with the default settings, nor is there a way you could configure it so it works in a usable way without highlighting every frequently occurring letter in every keyword too.

0

Share this post


Link to post
Share on other sites

Since I've switched to DVORAK-DEV I sometimes find myself doing very... sad things.

So, on DVORAK-DEV numbers are really difficult to do. They are... on the row you expect but in a different order, with 0-1 being passable, 2-3 ugh. I still don't remember the position of the others. It turns out 9 is on QWERTY-6.

Ah, and you have to hit SHIFT to do numbers, as default those buttons produce symbols.

 

So, when I don't have expressive names, I end up doing even worse stuff:

void Some::Function(uint argo, uint argi) { ... }

Because you see, o is a small 0. And i is 1. And 2 is... what about t? Cuz it looks like two isn't it? And 3 is e... uuuuh my head!

0

Share this post


Link to post
Share on other sites

So, if 'i' is just some loop variable, that's fine with me.  for i = 0; i < SomeMeaningfulNameHere; ++i

 

If the variable names are used because they are formulas to an equation, that's mostly okay, though I prefer it when at least the signature of the function is meaningful, even if later on in the function, distance is shortened to d, and startPoint is shortened to p0 or whatever.  If a link to the formula is in the code, that's super handy. 

 

I hate it when someone decides to get cute with variable names, there was a guy who had all his packet structures named after anime characters.  Or when every single variable is just a,b,c,d,e,f,g,h and so on, until it wraps around to aa,ab,ac.  (Though that's a sign that the code is probably overcomplicated, when you have more variables than the alphabet.)

0

Share this post


Link to post
Share on other sites

One letter variables are well suited for loops, or simple math formula, otherwise it's best to give an accurate variable name, even if it's long imo.

Edited by Vortez
1

Share this post


Link to post
Share on other sites

I understand single letter variables for constants and loops, but I have seen code like the one posted prior that look like alien language. I just don't get it. 

 

I mean, in math we represent quantities with variables, usually when those quantities are unknown or variable. But in programming we have freedom to give the variable a more descriptive name. I mean, it is useful to use single letter variables for formulas and perhaps this would be a justifiable use of single letter variables also. 

m =
 
x =
xx = x*x
 
b =
a =
c =
 
m*xx + b*x + 4*a*c

 

And if these variables represented numbers that are generated by some arbitrary process, then I can see how code can get real cryptic looking but still be understood easily. 

But it seems sometimes, for the sake of brevity, people use single letter variables or even non descriptive  abbreviations all over the place. I'd have a hard time myself if I didn't make it recognizable for later on. 

0

Share this post


Link to post
Share on other sites

Usually it's people who come from math backgrounds.  They are very used to, and comfortable with using single letter symbols to represent everything.  I would always notice it back when I was in school, and the math teachers would have some programming project, either a framework for us to use or a sample or whatever.  It was always single letter stuff.  While frameworks and samples from programming or game projects teachers, they would use descriptive variable names.

0

Share this post


Link to post
Share on other sites

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:

http://attractivechaos.awardspace.com/kbtree.h.html

 

then one thinks for a moment "hey, this is where C could use a more powerful preprocessor"...

then thinks for a moment more "I already wrote one before, it didn't help all that much, was inconvinient to use, and generally ended up not really used much...".

 

but, yes, sadly I have done this sort of thing before, just not usually this much at once, in a few cases (typically for statically-typed interpreter logic and similar, where basically otherwise similar logic has to be repeated endlessly for N-way combinations of types).

0

Share this post


Link to post
Share on other sites

Use longer names instead of single letter variables. Consider replacing

 

a with alpha

b with beta

d with delta

 

etc.

I do hope you are being sarcastic

0

Share this post


Link to post
Share on other sites


I do hope you are being sarcastic

 

Nope.  I do the same with indexes:

 

[tt]i[/tt] with [tt]idx[/tt]

[tt]j[/tt] with [tt]jdx[/tt]

[tt]k[/tt] with [tt]kdx[/tt]

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