20
u/k0ns3rv May 19 '15
The thing that bothers me the most about this code is probably that the first three lines are completely useless since the results are overridden in the next three lines
27
u/jdllama May 19 '15
Hold on, I can shittily Devil's Advocate this.
There's a mathematical concept that says that there are an infinite number of numbers between 1 and 2, just as there are the exact same number of numbers between 2 and 3. However, this means that the numbers between 1 and 3 must be even MORE infinite.
Think about how many numbers there are between 1 and 60! There's gotta be, like, a hundred, if not more! So of COURSE they have to be careful and define ONLY the ones they want!
I salute you, mysterious programmer. Thank you for not taking all of reality to calculate this.
6
u/BobertMcGee May 19 '15
Someone has read The Fault in our Stars...
Too bad Hazel was wrong about those infinities.
5
u/jdllama May 19 '15
...Wait, that's...that's in Fault in our Stars?
Fuck.
OK, I hereby withdraw my argument, Your Honor. It seems my defense is also discussed in Young Adult novels.
(I actually haven't read it, so it's a coincidence.)
3
u/BobertMcGee May 20 '15
Hazel uses it as a metaphor in the book. But, as other math nerds have pointed out, the infinite sets between 1 and 2, and 1 and 3 are actually the same size.
1
u/NotAnApron May 20 '15
Could you explain why they don't have different cardinality? /confused /tired
2
u/BobertMcGee May 20 '15
Here's someone else explaining it. http://bakingandmath.com/2014/07/08/the-fault-in-the-fault-in-our-stars-cantors-diagonalization-argument/
0
1
u/dotMX May 19 '15
The quantity of numbers between 1 and 2 is the same as between 2 and 3, 1 and 3 or between any integer and any integer. It's called aleph-0 and is the smalles infinite number.
7
5
u/maxximillian May 19 '15
That's not aleph-zero. Aleph null is the countably infinite. Example: the Cardinality of the set of all even whole numbers is equal to the Cardinality of the set of natural numbers is equal to the Cardinality of the set of all integers.
1
u/crazyeddie123 May 19 '15
I thought the number of integers was smaller than the number of real numbers between two integers.
-1
u/spencer102 May 19 '15
Quantity is not the same thing as cardinality. You're wrong. There are certainly more numbers between 1 and 3 the between 1 and 2.
7
6
u/stevengrissom May 19 '15
An optimization so he doesn't have to waste any cpu time calculating it, clearly. /s
I have to imagine this was an intern or fresh out of college or something. Pretty hilarious.
1
u/An2quamaraN May 22 '15
What is the beautiful country you live in where such code is "excepted" from an intern or fresh grad? I could apply for senior dev straight away!
6
u/solatic May 19 '15
So I'm not an Objective-C developer but maybe I can kind of defend this?
So apparently the first three lines are unnecessary. Fine. Can you construct these arrays with loops? Fine.
But what I first thought when I saw this is an attempt to create a more restricted time type, which eliminates an entire class of bugs. Imagine that you just represented hours and minutes as unsigned integers - is 14:30 PM a valid time? Only on a 24-hour (not 12-hour American-style) clock. Is 14:30 AM a valid time? No. Is 25:00 a valid time? No. Is 2:100 a valid time? No. You need to write a validation function and remember to call it whenever you use a time, which is bug-prone.
Or, you can explicitly define the range of possible values from which a time can be created - like an enum. And if you only ever create values based on that enum, then those values are guaranteed to be valid, so you'll never mistakenly create a bug from an invalid value, unless you mistakenly explicitly defined an invalid value in the enum. Of course it goes without saying that this is extremely prone to premature optimization, but still.
So since I don't know Obj-C - does that look like an enum to you guys at all? I just know that you couldn't define an enum's range of values in a for loop in Java, you'd have to define public enum Minutes { ZERO(0), ONE(1), TWO(2), ... FIFTY_NINE(59); ... /* constructor and helper methods here */ } I mean, in the real world you'd just use a library class, but that means that the code isn't shitty, just wasteful.
1
u/dvidsilva May 21 '15
But then xe's creating non standard times. When xis boss/client asks xim for something like "lets add it so the people can search by date their appointments" xe will have a bad time.
1
u/LukaLightBringer May 27 '15 edited May 27 '15
One problem is hh:mm:60 can be a valid time assuming this is to mirror the clock time which this can't represent.
5
May 19 '15
Can someone explain what I'm seeing here?
15
May 19 '15
Programmer sets three arrays to some value.
Programmer goes on to overwrite those array values with a long array of sequential numbers making the previous three lines pointless and a waste of space.
This leads us to believe said programmer has no idea how to use loops of any kinds.
3
May 19 '15
Okay, this makes sense. The @ symbols just make it look very weird and the array creation is very unfamiliar to me.
2
2
May 19 '15
This is an elegant way to never have to test whether or not you have to output a 0 before the minutes or hours. Because we all know that printf() is just full of buffer-overrun vulnerabilities.
5
May 19 '15
What the actual fuck? What language is this?
27
2
u/RuthlessTomato May 19 '15 edited Apr 01 '24
coherent angle attractive obtainable plants gray overconfident seemly north live
This post was mass deleted and anonymized with Redact
2
May 19 '15
I can only think of ons reason to do this, for performance. It is slightly faster to have all of this in memory instead of computing it. But unless you're working with very limited hardware (in terms of processing speed), there are no benifits. At least, none I can think of...
1
1
1
1
-5
u/oddlord May 19 '15
what bugs me the most is that hours starts from 1 and minutes from 0... do you even consistency?!
14
6
0
May 19 '15
[deleted]
7
u/sleepahol May 19 '15
It's really just standard camel case in programming but it does start to look strange when you're using abbreviations or words that have specific capitalization. Personally, I can't quite figure out how to use "iOS" in a variable name.
5
u/5HT-2a May 19 '15
When I write in lower camel case, I still retain the capitalization of abbreviations, proper nouns, etcetera... e.g.
iOSVariableandHTTPVariable.3
u/sleepahol May 19 '15
What if it's more appropriate at the end of the variable name?
isiOS,isiOSDevice? That works, but still looks weird.2
1
3
u/the_omega99 May 19 '15
I do the opposite. Treating abbreviations, weird things like "iOS", and so on as normal words makes it very easy to be consistent and ensures that I can easily tell where words are in the identifier. I just never need to be able to recognize the case otherwise.
Examples:
XmlHttpRequest,demoIosBrowser,iceCandidates1
u/5HT-2a May 19 '15
Hah, see to me that looks crazy. Maybe I've just been brainwashed by Apple and their naming scheme.
1
u/myusernameisokay May 19 '15
Here is the google style guide on camel case, which covers some of these cases.
iOSVariable becomes iosVariable, HTTPVariable becomes httpVariable, if you want lower camel case.
7
48
u/TheSlimyDog May 19 '15
I can't even begin to imagine why you'd need something like that. It works... but why?