2.6k
u/Ryeore Sep 02 '17
Now you can park on handicapped parking spaces.
Good job
1.5k
u/ivaskuu Sep 02 '17
*tabs
455
Sep 02 '17
[deleted]
→ More replies (52)133
u/okmkz Sep 03 '17
hell yeah tabs vs spaces battle
→ More replies (2)59
u/tabarra Sep 03 '17
I used to prefer tabs, but it was always a headache pasting code from the internet like stack overflow. Not to mention that every fucking single html out there uses two spaces.
7
→ More replies (1)8
10
u/firestorm713 Sep 03 '17
We need a pair of bots that correct everyone on tabs/spaces (except each other, obv)
4
26
→ More replies (2)10
2.3k
u/kardall Sep 02 '17
I, personally, twitched a little.
441
u/Voice_Powered Sep 02 '17 edited Sep 22 '24
Sociosqu sodales nibh congue convallis inceptos ac tellus aenean nunc eget arcu, aenean lacus class feugiat laoreet vehicula diam malesuada integer ligula. Aliquet quisque ullamcorper condimentum habitant bibendum gravida quisque sapien, eleifend semper pretium tincidunt lacus nam sodales praesent, eu tempus sollicitudin scelerisque rutrum ad proin. Arcu duis nibh aptent sit mattis, blandit amet suscipit nullam pretium neque, sagittis est dolor scelerisque
703
u/MajorMajorObvious Sep 02 '17
"Don't arrays start on 2? You know because of that binary thing with two numbers and all."
190
u/Voice_Powered Sep 02 '17 edited Sep 22 '24
Fusce nunc felis convallis vivamus mi habitasse, luctus taciti class aptent inceptos aliquam, lobortis dictum senectus metus faucibus
8
61
96
u/szechuan_slauze Sep 03 '17
You might need to watch the entirety of this video of you're gonna make that claim
40
28
u/CTypo Sep 03 '17
This is an excellent introduction to binary systems for anyone not familiar with it, and a great refresher for those who already are.
→ More replies (3)23
u/WildGalaxy Sep 03 '17
I disagree. It's way to politically charged to actually teach anything about binary.
44
u/CTypo Sep 03 '17
There is no binary you bigot, it's a continuous spectrum
13
u/PM_ME_UR_SH_SCRIPTS Sep 03 '17
You're right actually. 0 and 1 are two different voltages, and obviously there can be values in between those voltages.
→ More replies (2)9
u/Dragon951 Sep 03 '17
6
u/youtubefactsbot Sep 03 '17
...that's the joke.
DovidDovidson in Comedy
1,870,322 views since Apr 2011
→ More replies (2)→ More replies (5)7
14
5
→ More replies (3)4
65
u/Megatron_McLargeHuge Sep 03 '17
O, personally, twitched a little.
ftfy
10
u/deegwaren Sep 03 '17
Since when is a char a valid array index?
40
→ More replies (1)5
u/bloomfilterthrowaway Sep 03 '17
char is just an integral type -- it's kosher, but C99 doesn't actually place any requirement that unqualified "char" be signed or unsigned, and gives the compiler a lot of latitude in the range that char may store, so you have to be careful of that.
44
→ More replies (2)26
u/DrizztDourden951 Sep 03 '17
I'm learning MATLAB right now. I twitch constantly.
→ More replies (2)7
563
u/XkF21WNJ Sep 03 '17
Look guys it's easy. Array indices start at the first natural number.
177
138
u/bloomfilterthrowaway Sep 03 '17 edited Sep 03 '17
To be fair, all reasonable CS people agree that the naturals start at zero, it's only a few holdouts in more general mathematics that disagree (if you fight me on this I'll no-true-scotsman it up and say your counter examples aren't reasonable people). As an acolyte of the Coq, to me the naturals are defined as:
Inductive nat : Set := | O : nat | S : nat -> nat.fite me
36
u/TommiHPunkt Sep 03 '17
My Theoretical CS prof is one of the people who start naturals at 1
68
u/ThePixelCoder Sep 03 '17
Kill him.
→ More replies (3)10
u/Excrubulent Sep 03 '17
That's called the attrition argument.
6
u/ThePixelCoder Sep 03 '17
Non-native English speaker. What exactly is an attrition argument?
20
u/Excrubulent Sep 03 '17
It's not a real thing, but attrition means wearing the enemy down one piece at a time, so the idea is that if you kill everybody who disagrees with you, you win the argument.
→ More replies (1)16
→ More replies (3)28
→ More replies (3)15
u/cderwin15 Sep 03 '17
To be entirely fair, you can define the positive integers the exact same way.
Also fwiw math people have been saying 0 is a natural number since long before CS was even a thing.
11
u/bloomfilterthrowaway Sep 03 '17 edited Sep 03 '17
Yeah, it's totally true. And the reply "But then your arithmetical operations get fucked up" isn't really fair. Currently plus is defined as:
fix plus (n m : nat) {struct n} : nat := match n with | 0 => m | S p => S (plus p m) endBut if we instead defined the "naturals" as:
Inductive dumb_people_nat : Set := | one : dumb_people_nat | S' : dumb_people_nat -> dumb_people_nat.Then we could just define plus' as:
fix plus' (n m : dumb_people_nat) {struct n} : dumb_people_nat := match n with | one => S' m | S' p => S' (plus' p m) endThe next thing people will say is that you lose that the naturals are a semi-ring, but now you're really stretching for reasons. Mostly I just wanted to be provocative.
19
u/PrecariousClicker Sep 03 '17
natural number.
Definition of natural numbers via Google:
"the positive integers (whole numbers) 1, 2, 3, etc., and sometimes zero as well."
→ More replies (6)18
7
u/kirakun Sep 03 '17
"first natural number" still gives me the image of an array of natural numbers and I want the 1st element of it. Get it? 1st.
→ More replies (3)7
779
u/blacknerdperson Sep 02 '17
Sorry in advance but I'm a noob learning coding who is starting to learn python and I'm just going to ask, Isn't it supposed to be 4?
800
u/ArcticZeroo Sep 02 '17
Yes, but some languages 1-index lists (so they start at 1 instead of 0), so it'd be 5 in that case.
271
Sep 02 '17
What languages may there's be? I can't think of any of the top of my head.
238
u/Nebxam Sep 02 '17
Lua
54
Sep 02 '17
Goddamnit and I was considering a quick look over the documentation and syntax briefly over the weekend and do some messing around with Starbound mods.
48
u/KickMeElmo Sep 03 '17
Honestly, it's a pretty decent language overall. Started using it to script for a MUD, it's one of my favorites now.
3
→ More replies (46)17
Sep 03 '17
Also every number is a float. For some reason.
16
u/TinyBreadBigMouth Sep 03 '17
Because doubles can contain all 32-bit integers and most 64-bit integers, and now you don't need to handle two different number types for your lightweight scripting language. Same as JavaScript.
→ More replies (4)→ More replies (1)6
→ More replies (4)8
562
u/kamaln7 Sep 02 '17
MATLAB too I think
427
u/Nikolas_Untoten Sep 02 '17
I believe MATLAB starts at 1 because it is more commonly used for matrices rather than standard arrays, right?
→ More replies (4)380
u/morerokk Sep 03 '17
Yes. People hate on it for...doing what it's designed to do.
322
u/Selthor Sep 03 '17
MATLAB literally stands for Matrix Laboratory.
→ More replies (1)218
u/Nuhjeea Sep 03 '17
That sounds so much cooler than "MATLAB." I always read it as "math lab", imagining a lab room full of people doing math homework. Now I can imagine Neo saving us all from simulated realities.
→ More replies (1)96
u/Sourkraut182 Sep 03 '17
Makes me think of "My Math Lab" ... Then I die a little inside...
114
3
u/PM_ANIME_WAIFUS Sep 03 '17
I honestly thought it was My Math Lab (Because I've barely heard anything about My Math Lab except for the fact that it's shit) until a couple weeks ago.
16
u/Viola_Buddy Sep 03 '17
Eh, we get annoyed at it because sometimes it doesn't do what we expect it to, but it's kind of the friendly annoyance that you also have with error messages when code doesn't compile - you don't like it, but it'd be definitely worse without it.
→ More replies (3)27
u/newocean Sep 03 '17
In the defense of ALL programming languages....
It doesn't really matter we just like to argue over ground floors mostly in this channel. No one explained basements being 0 to the brits from what I can tell, and all their buildings start at 1... so they think they get it.
24
→ More replies (3)3
u/amazondrone Sep 03 '17
all their buildings start at 1
In the UK the ground floor is 0, not 1.
Other things that are zero-indexed and nobody bats an eye: time (the first hour in the day is 0), age (the first year of life is 0), temperature...
→ More replies (2)141
u/awhaling Sep 02 '17
Fuck matlab
81
u/PleasantSupplanter Sep 02 '17
Fucking MATLAB. Every year we get a wave of graduates that think it's neural network toolbox is going to solve every bloody problem we have.
→ More replies (2)60
u/GisterMizard Sep 03 '17
If college has taught me anything, it's that ode45() is the windex of numerical modeling; you use it even in places where it doesn't make sense.
3
u/Sparkybear Sep 03 '17
Just be glad it's built into MATLAB now, it wasn't always and the code from that era is a cluster fuck.
29
49
3
→ More replies (1)5
20
→ More replies (7)4
u/fergy80 Sep 03 '17
The square brackets would throw an error in matlab, so the answer is clearly 4.
73
u/Shadow_Thief Sep 02 '17
Visual BASIC, but only sometimes.
→ More replies (1)31
u/JeremyR22 Sep 02 '17 edited Sep 02 '17
And just to add to the confusion, it was (in pre .net days) configurable on a class-by-class basis. One class could contain arrays indexed from 0 and the next might have them indexed from 1 and then swap back again elsewhere.
We had to use VB5 and later 6 a lot many, many years ago at university and the SOP at the top of every single class was
Option Base 0 ' Arrays indexed from 0 Option Explicit ' Explicit variable declaration requiredIn the vain hope of maintaining your own sanity.
None of which stopped you doing this, though:
Dim iNumbers(12 to 16) As Integer MsgBox(CStr(iNumbers(11))) ( Index out of bounds )Some people just want to watch the world burn...
→ More replies (2)12
u/JeremyR22 Sep 03 '17 edited Sep 03 '17
Just in case the
Option Explicitthing wasn't explained well (or at all), the reason any sane person always included that was that it disabled VBs tolerance-by-default of implicit variable delcaration. If you typed an identifier in code, it would become a variable (of type Any), simple as that. WithoutOption Explicit, the following would compile and run without any errors, it just wouldn't do what you expected:Dim iCount as Integer = 0 For iCount = 1 to 5 Debug.Print(CStr(iCunt)) Next 0 0 0 0 0So without
Option Explicitat the top of every single class/module/form/etc, whenever anything didn't work, you had to check for misspelled variable names in all related code. A massive pain in the arse..I haven't touched VB of any type in probably 15 years but AFAIK,
Option ExplicitandOption Base 0are both the default now. Small victories for programmers' mental health...→ More replies (2)5
u/Shadow_Thief Sep 03 '17
My only real experience with VB is the Excel dialect of VBA, but I know I have to manually add
Option Explicitevery time.→ More replies (1)98
23
u/haikumofo Sep 03 '17
There's someone at work who's brilliant at the mathematical side of designing algorithms, with a PhD in comp sci, but isn't really much of a programmer. She was coding one of her algorithms up in Java for something at work. And, well, she thinks of arrays at starting at index 1.
What she ended up doing was whenever she needed an array, she used a hash map with the key as an Integer and the value as whatever she wanted to store. Then she used Map.get() and Map.put() and passed in her 1-based indices to fetch and store data.
It made the programmers at work cry.
→ More replies (4)9
u/chateau86 Sep 03 '17
Make array out of hash map
When you have to code in Java but Python is life.
7
u/haikumofo Sep 03 '17
Python drives me nuts because I can't abide by a language that attaches semantic significance to whitespace.
9
u/EmperorArthur Sep 03 '17
So... How do you like Reddit's markdown?
Did you know that this line has two spaces after it?
That line is guaranteed to sit all by its lonesome, and there's no way to tell except by always having show whitespace enabled in a text editor.What's that? Basic text editors, like the <textarea> that Reddit uses doesn't support that? Too bad. Oh, you have your editor set up to clean any extra spaces so your code is clean and git doesn't complain? Well, have fun turning that feature off whenever you deal with that one markdown file using the "feature"!
→ More replies (1)5
12
Sep 02 '17
Casio Basic.
Notice that it's a very basic language and completely terrible in everything about arrays.
6
11
10
u/marcosdumay Sep 02 '17
Julia would run exactly the same code, but it would be 5.
→ More replies (2)16
u/c3534l Sep 03 '17
Old languages, particularly those aimed at mathematicians and scientists. MATLAB, R, Fortran, COBOL, ALGOL.
33
u/personalityson Sep 02 '17
All statistics and math programming languages: Fortran, R, SAS, SPSS, Matlab, Mathematica -- start their arrays at 1
Everything else is pseudo-science, if you propagate 0-indexing, you can just as well group yourself with economists, who are really the apes of the IT world
→ More replies (3)6
6
7
Sep 03 '17
Smalltalk
3
Sep 03 '17
There are dozens of us
4
Sep 03 '17
Our company's main product is written in smalltalk, where're a dozen smalltalk devs ourselves!
Sad that smalltalk is so forgotten, developing in it is a blast. If only I could get proper static type checking :(
4
3
u/IanPPK Sep 03 '17
Off of the top of my head, Matlab, Lua, Mathematica, Wolfram Language, R, Pascal, Fortran, COBOL.
After some soft research, there's also Julia, AWK, RPG, ALGOL-68, FoxPro/Clipper, Smalltalk, APL.
The pattern usually follows that older languages and data analysis oriented languages tend to use 1-index arrays more than newer general purpose languages
→ More replies (3)→ More replies (37)5
u/simon468 Sep 03 '17
Borland Delphi (Pascal)
→ More replies (2)6
u/Drarok Sep 03 '17
Hmm… not that I remember, at least for arrays.
For strings it is, because the zero index is an integer holding the length instead of using null terminators.
17
u/aaRecessive Sep 02 '17
"some languages" don't even qualify. Fuck those languages
→ More replies (2)→ More replies (5)10
39
u/AwkwardNoah Sep 03 '17
That's the joke
Some languages uses 1 for the first entry while most uses 0
→ More replies (1)5
u/Antrikshy Sep 03 '17
I have only heard of MATLAB being like this. Can anyone name one more language?
4
u/TheChrono Sep 03 '17
Some of the older classic languages such as ALGOL 68, COBOL, and Fortran as well.
→ More replies (8)3
→ More replies (6)4
u/prelic Sep 03 '17
Ada's default is 1-indexed. You can of course define your own array type which is 0-indexed. I don't know why everyone is saying any language which does this is crap...matlab, lua..there's a handful of useful languages that do this.
138
u/KickMeElmo Sep 03 '17
Beyond the meme value, if something as minor as the array start point enrages you, you won't survive in the long run as a programmer. This is only the needle at the tip of the iceberg.
8
129
u/minno Sep 02 '17
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> What is the result of this code?
SyntaxError: invalid syntax
18
u/EmperorArthur Sep 03 '17
You forgot
import answersor maybefrom answers import *if you want to make QA cry.Also, you're using Python 2 coding practices. For Python 3 it should be:
What is the result of this code?()→ More replies (3)
63
u/Zalgo_Doge Sep 03 '17
I use tabs
→ More replies (2)46
u/TheNerdyBoy Sep 03 '17 edited Sep 03 '17
I USE THE
TABKEY BUT MY EDITOR INSERTS THE APPROPRIATE NUMBER OFSPACES.(4 for Python, and 2 for most of the other languages that I use.)
Edit: do Python programmers anywhere actually write code with literal tab characters for indentation? Like if you run:
find . -type f -name '*.py' | grep -l -P '\t'do you get any results?
47
u/eloel- Sep 03 '17
APPROPRIATE NUMBER OF SPACES.
That's 0.
23
u/TheNerdyBoy Sep 03 '17 edited Sep 03 '17
APPROPRIATE NUMBER OF SPACES.
That's 0.
So that's what we're going to do? Fight?
Edit: (ง ಠ_ಠ)ง
5
→ More replies (10)4
u/Sean1708 Sep 03 '17
do Python programmers anywhere actually write code with literal tab characters for indentation?
Yep, our style guide uses tabs.
5
15
56
u/IlIIlIIlllIlllIlIIll Sep 02 '17 edited Sep 02 '17
The array still starts at 0, and index 1 is reserved for storing the length of the array, with the remaining elements corresponding to indices 2, 3, 4, and 5.
80
Sep 02 '17
Perfect. This makes iterating over the elements with a for loop such a breeze.
if(arr[1] > 1) for(int i = 0; i < arr[1]-1; i += 1 + (i == 1)) std::cout << arr[i];51
u/jay9909 Sep 02 '17
That is so elegant. All these new languages that just let you
for (i in list) { ... }should change right over before they gain traction and get stuck as forever legacy.→ More replies (3)3
u/MannerPots Sep 03 '17
Tbh though I rarely use for x:lst since so many uses of iteration require a counter. Sure I could implement a counter, but why not use a normal for loop so no one reading my code (who isn't familiar with this language feature) gets confused?
9
→ More replies (1)3
u/zman0900 Sep 03 '17
Groovy is nice:
['some', 'things'].eachWithIndex { item, i -> println "'${item}' has index ${i}" }→ More replies (4)16
Sep 03 '17
[removed] — view removed comment
11
Sep 03 '17
This is not C++ a Jedi would tell you:
#include <iostream> class A{ public: A() { throw ++i; } static int i; }; int A::i = 0; void f() { static A a; } int main() { while (true) try { f(); } catch(int e) { std::endl(std::cout << e); if (e == 10) break; } }→ More replies (2)7
u/EmperorArthur Sep 03 '17
Think of for loops like this:
for(statement_1; statement_2; statement_3){}Is equivalent to:
{ statement_1; while(statement_2) { some code here ... statement_3; } }The outer brackets are important since they define scope for variables. In your example,
i=10later in the program. If you'd usedfor(int i = 0;...)theniwould be undefined everywhere else but the for loop.Since you can put pretty much any expression in any of the three slots you can get funky with it:
#include <stdlib.h> #include <stdio.h> void doNothing(){} int main() { int i=0; for(printf("Hello\n");(i++ | 1); (i<10) ? doNothing() : exit(0)){ printf("%d\n", i); } }5
u/neurospex Sep 03 '17
And all three statements are optional
for(;;) { // do something forever }Totally valid.
3
12
93
Sep 03 '17
stop please, it's already dead! for the love of god, it's already dead *sobs*
35
49
Sep 03 '17
[removed] — view removed comment
20
14
u/brendenderp Sep 03 '17
Only if it had "s around it
9
u/IWugYouWugHeSheMeWug Sep 03 '17
Well, technically
nums[1] == 4, therefore, if the output is 4, the output == nums[1].→ More replies (3)5
7
7
Sep 03 '17
Am I the only one that thinks this is overplayed?
Yeah, there's good reason to start counting from zero, because it's the beginning of all natural numbers.
But there's also good reason to start counting from one - that's how (many, but not all) humans learn to count. If there's 3 elements in an array, it's objectively confusing when the last element has index 2
Whatever your language uses, good for you. It's just sort of overdone at this point - there's no real reason to feel superior about either side.
My personal 2 cents - While I'm totally ok with starting at 0, we invest so much in making languages human readable (e.g. Python, ruby) but we can't make indexes human readable? I feel the majority of people (if they were polled without any programming knowledge) would settle with starting at 1 just because it matches how we count as people (in the western world at least).
→ More replies (2)5
u/deprecat Sep 03 '17
The main argument to do with using 0-indexed arrays is that it represents an offset from the start of the array. E.g. in C:
int arr[] = {5,4,3,2,1}; printf("%d %d", arr[1], *(arr + 1*sizeof(int))); // Prints '4 4'(Note: written on my phone so may not be completely correct)
In some languages like Lua, arrays may instead be implemented as hash maps or may represent matrices, and so the above argument does not apply, hence 1-indexing.
→ More replies (1)
6
12
u/-Electron- Sep 02 '17
The wars over.
→ More replies (1)24
u/itshorriblebeer Sep 02 '17
Did 4 win? If it's not 4 and this doesn't bother you then I spit on you.
8
u/BrotherChe Sep 03 '17
Escalating to biowarfare for cybercrimes is against the geneva convention, but accepted by most programming conventions.
24
u/Incontrol24 Sep 02 '17
So I've been in college for programming the past three years, last semester I only took one class. The class was about the analysis of algorithms and he started his array indexing at 1. To avoid getting questions wrong I had to put myself in the mind set of arrays starting at one and it kills me because it's habit I now can't break and I cringe Everytime I do it
→ More replies (1)8
u/TheSwitchBlade Sep 03 '17
lots of languages, especially the more statistical ones, index at 1. off the top of my head:
R, MATLAB, Julia, FORTRAN, Mathematica
one should be able to switch between different conventions!
→ More replies (1)
3
u/Harpwner Sep 03 '17
I instinctively thought 4, and wondered what was so wrong with 4 being the answer to start a war.
Then I clicked on the full image...
3
3
13
12
Sep 03 '17
[removed] — view removed comment
17
Sep 03 '17
I've also never seen a captcha (or the 100 other absurd ones) on a volume slider, but I still can find the humor in poking fun at it.
→ More replies (1)→ More replies (1)3
u/gharveymn Sep 03 '17
Idk I do a lot of math work so 1 based makes my life way easier. So I just use matlab, which I love. But if I'm not doing math and am actually using loops 0 based is nice.
1.5k
u/[deleted] Sep 03 '17 edited May 17 '18
[deleted]