Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ugh! Your shorthand is too short!

  • You cannot reply to this topic
46 replies to this topic

#41 swiftcoder   Senior Moderators   -  Reputation: 8171

Like
0Likes
Like

Posted 21 February 2014 - 05:44 AM

Unicode identifiers, FTW.

 

At least as long as you are developing on a Mac (after all these years, I still have no idea how to type greek letters on a PC keyboard).


Tristam MacDonald - SDE II @ Amazon - swiftcoding        [Need to sync your files via the cloud? | Need affordable web hosting?]


Sponsor:

#42 Orymus3   Crossbones+   -  Reputation: 4363

Like
1Likes
Like

Posted 21 February 2014 - 01:48 PM

I keep seeing it happen, and the problem is that some people actually believe this is optimizing code. The problem becomes code readability, which hurts in the long run, especially as other developers get on with the project.

I don't think that shortcutting var names really optimizes the process. To be frank, we spend a lot more time reading code than writing code, so we should optimize readability, no ease of writing it. Just my 2 cents.



#43 swiftcoder   Senior Moderators   -  Reputation: 8171

Like
1Likes
Like

Posted 21 February 2014 - 02:01 PM


To be frank, we spend a lot more time reading code than writing code, so we should optimize readability, no ease of writing it.

Plus, if there is one thing modern compilers are good at optimizing away, it is variable names :)


Tristam MacDonald - SDE II @ Amazon - swiftcoding        [Need to sync your files via the cloud? | Need affordable web hosting?]


#44 Tutorial Doctor   Members   -  Reputation: 990

Like
0Likes
Like

Posted 12 March 2014 - 01:54 PM

I knew this would happen. I am starting to see why people try to keep their code as short as possible. I mean, when you are writing hundreds and hundreds of lines of code, it gets annoying typing in long names.

Now, in the event of a tutorial, I think names should be longer and more descriptive. I actually think names should always be descriptive anyhow (short or not). Perhaps the reader doesn't have to get it, but the writer should. Now, if you are not maintaining the code, then you probably want to make them descriptive.

Or what if you want to refer to the code some time in the future? Will you recall the meanings of the variables then if you perhaps want to modify it a bit?

I am trying to create a naming convention so that I can keep my stuff consistent throughout, yet easy to maintain. Certainly when doing math functions and iterations it is reasonable to use single letter variables.

This post was a result of me browsing through someone else's code for a small GUI they made using lua. I just need to be more modular perhaps.

They call me the Tutorial Doctor.


#45 TheComet   Members   -  Reputation: 1156

Like
2Likes
Like

Posted 12 March 2014 - 05:59 PM

I've found that a lot of code is written by mathematicians or physicists, and on paper the formulas all have one-letter-variables, so they will copy that one-to-one when they implement it in code.

 

For instance, an electronic engineer will know that the formula for calculating a charging voltage of a capacitor in an RC circuit is:

U = U0 * (1-e^(-t/(R*C)))

 

So in code, I will reflect exactly that:

double U = U0 * 1-pow(e, 0.0-t/(R*C));

Every non-electronic engineer is going to look at that and go "WTF IS THIS CRAP".

 

I've had moments where I've done the same thing at first glance, but as soon as I research the algorithms being used, the variable names begin to make a lot of sense.

 

 


I mean, when you are writing hundreds and hundreds of lines of code, it gets annoying typing in long names.

One word: auto-complete.


YOUR_OPINION >/dev/null


#46 Tutorial Doctor   Members   -  Reputation: 990

Like
0Likes
Like

Posted 12 March 2014 - 07:50 PM

Yeah comet, that is what I saw. Even for variables that aren't math formulas I see why such short names were used, and I have started to do the same myself. I am still going to stick with doing longer names for tutorials. 

 

I don't think I have auto-complete, as I am using a plain text editor, without the help of a big IDE. Sometimes I do use Notepad++ which might have auto-complete, but mostly I use Scite. 


They call me the Tutorial Doctor.


#47 l0calh05t   Members   -  Reputation: 581

Like
2Likes
Like

Posted 13 March 2014 - 06:23 AM


For instance, an electronic engineer will know that the formula for calculating a charging voltage of a capacitor in an RC circuit is:

U = U0 * (1-e^(-t/(R*C)))



So in code, I will reflect exactly that:

double U = U0 * 1-pow(e, 0.0-t/(R*C));

Every non-electronic engineer is going to look at that and go "WTF IS THIS CRAP".

 

The electrical engineer might wonder though why you wrote 0.0-t/(R*C) instead of just -t/(R*C) (is -0.0 an issue for the pow function you are using?). And the computer scientist might wonder why you are using pow(e,x) instead of exp(x) which is usually faster. And both might notice you forgot an opening parenthesis wink.png In any case it wouldn't hurt anyone to write

 

double voltage = starting_voltage * (1. - exp(-time/(resistance * capacitance)));

 

Instead, as then both the electrical engineer and the computer scientist would probably have a rough idea what its about, at the cost of only a few keystrokes (which tend to be fairly cheap wink.png).


Edited by l0calh05t, 13 March 2014 - 06:28 AM.






PARTNERS