Programmers: Your longest lines of code?

Xerol

Emperor
Joined
Oct 6, 2002
Messages
1,542
Location
In an IDE.
Usually programmers try to simplify things. To me, that means doing as much as possible in each line of code.

This sometimes results in super-long functions:

Code:
DECLARE SUB CreateTextObject(x as double, y as double, mx as double, my as double, ax as double, ay as double, c1 as integer, c2 as integer, text as string, font as integer, just as integer, age as double)

I tend to use custom font functions a lot too:

Code:
    PrintFontGrad 400+player.mx*1.5, 32+player.my*1.5, gametitle$, 1, rgb(5+int(sin(frame)*5), 5-int(sin(frame*2)*5), 5+int(cos(frame*3)*5)), rgb(5-int(sin(frame)*5), 5+int(sin(frame*2)*5), 5-int(cos(frame*3)*5)), 0, 0
Code:
    PrintFontGrad 400+player.mx*.5, 32+player.my*.5, gametitle$, 1, rgb(55+int(sin(frame)*50), 55-int(sin(frame*2)*50), 55+int(cos(frame*3)*50)), rgb(55-int(sin(frame)*50), 55+int(sin(frame*2)*50), 55-int(cos(frame*3)*50)), 0, 0
Code:
    PrintFontGrad 400-player.mx*.5, 35-player.my*.5, gametitle$, 1, rgb(155+int(sin(frame)*100), 155-int(sin(frame*2)*100), 155+int(cos(frame*3)*100)), rgb(155-int(sin(frame)*100), 155+int(sin(frame*2)*100), 155-int(cos(frame*3)*100)), 0, 0
Code:
PrintFontGrad 400, 284, "- - - PAUSED - - -", 1, rgb((155+int(sin(frame)*100))*cmult, (155-int(sin(frame*2)*100))*cmult, (155+int(cos(frame*3)*100))*cmult), rgb((155-int(sin(frame)*100))*cmult, (155+int(sin(frame*2)*100))*cmult, (155-int(cos(frame*3)*100))*cmult), 0, 0

Doing a lot in one IF statement makes things a bit more efficient:

Code:
if aliens(n).hp < alientypes(aliens(n).alientype).maxhp + level^2*alientypes(aliens(n).alientype).hpbonus and aliens(n).hp > 0 then aliens(n).hp = aliens(n).hp + alientypes(aliens(n).alientype).regen * fpsrate
Code:
if abs(aliens(m).x+16-(projectiles(n).x+projectiletypes(projectiles(n).projectiletype).size/2)) < 16 and abs(aliens(m).y+16-(projectiles(n).y+projectiletypes(projectiles(n).projectiletype).size/2)) < 16 then
Code:
if batteries(n).charge > 0 then line (batteries(n).meterx1, batteries(n).metery1)-(batteries(n).meterx1 + batteries(n).meterwidth, batteries(n).metery1 - batteries(n).charge/batteries(n).maxcharge*batteries(n).meterheight), rgb(0, 255, 0), bf

And I'm always pushing the right boundary of the IDE with calls like this:

Code:
SpawnBullet (ship.x+cos(ship.dir+o*3.141592/180)*11, ship.y+sin(ship.dir+o*3.141592/180)*11, cos(ship.dir+(rnd-.5)/10 + o*3.141592/180)*(350+rnd*100-abs(o)), sin(ship.dir+(rnd-.5)/10 + o*3.141592/180)*(350+rnd*100-abs(o)), OWNER_PLAYER, 1, (30-abs(o))/30+1)

So, do you have any hall-of-fame lines?
 
I find a single line of code somewhat relative, as different languages have different syntax, and you could make a variable as long as you want, or make the statements (even function, or entire program) as cryptic as you want. We did this once in our computer science 101 class. (the putting of everything on one line, not the bottom code)

Code:
for ( int i = 0; i < doStrings(m_SomeVar).getLength(); i++) { if (doStrings(m_SomeVar).char(i).HexValue > chars.GetLowRange()) && (doStrings(m_SomeVar).char(i).HexValue < chars.GetUpperRange()) { encryptStr += doSomeEncryption(doStrings(m_SomeVar).char(i), getEncryptionKey()); doSecondTask(); doThirdTask(withSomeVar); doFourthTask(withAnotherVar); doFifthTask(yetAnotherVar); } }

:D

Now, I really can't put any code from work though...
 
Simplifying doesn't necessarily mean long lines of code. Usually that means making it simple enough for just about anyone to follow it.
 
Maintainable code and readability are very important to me. So no extremely long lines.

I have extremely bad experiences maintaining rubbish code from others. I won't even call them programmers... they don't qualify.

All kinds of techniques that you can think of when writing unmaintainable code as a joke, they've used them. And stuff you can't even imagine. Like writing your own mutex in Java. Or their own int wrapper class that adds no functions.

They're lucky that I was asked to maintain their code after they left the company... or I would strangle them or smash their heads with their CRT monitors.
 
I think I might have used a MULU instruction once. ;)

HINT: Assembly language doesn't use long lines of code.
 
I write all my code in the full knowledge that someone *else* may (probably will) have to maintain it. Like kcwong, I have seen disasterous code written by others, so I make sure my code is *readable* and *maintainable*. That means no super long lines, no oddball constructions, plenty of comments, etc. ;)
 
You dont work long in the real world unless you learn real fast that simple and maintainable matters a lot more than "doing as much as possible in each line of code"

On a good day, over 60% of the lines in my programs are comments.
 
Back
Top Bottom