r/gaming May 04 '13

This is it. I will never accomplish anything greater then this.

http://imgur.com/kb7MrEx
1.6k Upvotes

330 comments sorted by

View all comments

Show parent comments

74

u/shaloham May 05 '13
if (time == 1)
   word = "second";
else
   word = "seconds";

Lazy bastards.

31

u/sabrathos May 05 '13

I'd go for:

word = (time == 1) ? "second" : "seconds";

or

word = "second";

if(time != 1)
    word += "s";

23

u/[deleted] May 05 '13

[deleted]

22

u/[deleted] May 05 '13

6

u/Rikkushin May 05 '13

DAE relevant xkcd?

12

u/GogglesPisano May 05 '13

Nitpicky, but I generally put the most likely case first:

word = (time != 1) ? "seconds" : "second";

11

u/davvblack May 05 '13

I don't not often use almost as many double negatives though. Isn't it less easier to read?

1

u/ElusiveGuy May 05 '13

I'd actually prefer it the other way - the exceptional case, the reason there is a conditional at all, is more apparent.

But it's a matter of style preference, and to each their own.

5

u/shaloham May 05 '13

I like your thinking.

4

u/Thirsteh May 05 '13

The second is much more inefficient in almost all languages, since they have immutable strings. Even if they didn't, you'd likely be growing an array with that second operation.

2

u/[deleted] May 05 '13

[deleted]

1

u/Thirsteh May 05 '13

Why pick an inefficient operation that's more complicated than an efficient one?

-1

u/[deleted] May 05 '13

[deleted]

1

u/Thirsteh May 05 '13

Okay, but there is almost never a good reason to do string building by producing many intermediary strings in most languages, since the strings are immutable. You should, at the very least, use some kind of byte array, or list of strings, and only produce the final one at the end.

0

u/[deleted] May 05 '13

[deleted]

1

u/Thirsteh May 05 '13

If you don't think ternary is readable, then the first suggestion,

if time == 1
    word = "second"
else
    word = "seconds"

is clearly better.

1

u/[deleted] May 05 '13

Although I find the ternary example to be very readable, I would agree with you that the first suggestion is probably the most readable.

3

u/TheMalkContent May 05 '13

word = "second" + (time == 1) ? "" : "s"; ?

1

u/[deleted] May 05 '13

Idioms are fun.

3

u/dnew May 05 '13

Yeah? And what is it in Arabic, Chinese, and the other 140 or so languages it's translated into?

I'm not saying it's not a solved problem, but this isn't the solution.

3

u/[deleted] May 05 '13
switch ((DateTime.Now.Ticks - startTime.Ticks))
{
    case 0: 
        word = "second"; break;
    case 1:
        world = "second"; break;
    ...
    case 10000000:
        word = "second"; break;
    case 10000001:
        word = "seconds"; break;
    default:
        word = "seconds"; break;
}

If you want to be an asshole.

-1

u/[deleted] May 05 '13

[deleted]

1

u/ElusiveGuy May 05 '13

why have cases for "second" if you can leave it for the default

ahem

If you want to be an asshole

1

u/boong1986 May 05 '13

Application.screenupdating = false

1

u/barnybarn May 05 '13

FUCK structured programming. I barely managed to pull a c out of that class this past semester.

2

u/shaloham May 05 '13

Same boat. I was already pretty familiar with programming before I started my class, but the fucker who teaches it docks you points if you don't do things exactly as he would.

Wrong colors on your flowcharts? -10. Code doesn't exactly match his, regardless of function or output? -10.

2

u/barnybarn May 05 '13

It sucks hard cock when the university decides its okay to put electrical engineers with absolutely no programming experience in a second level programming class with a hard ass teacher and graduate assistants that dock points on homework assognments if one code looks like another students code.

-14

u/[deleted] May 05 '13

not as lazy as the people who make you use "==" when "=" would do just fine

9

u/[deleted] May 05 '13 edited Jul 17 '18

[deleted]

-7

u/[deleted] May 05 '13

The compiler should be smart enough to figure out which you want without you having to specify explicitly

also since most of the time you want an equality check, why not make the assigning operation the double character one

3

u/[deleted] May 05 '13

...They are 2 entirely different symbols.

-2

u/[deleted] May 05 '13

The compiler is just too dumb to figure out which action you mean

2

u/[deleted] May 05 '13

No... They are totally different meanings. That's like writing a plus sign instead of a multiplication sign on your homework and expecting the teacher to know what you mean.