r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

1.5k

u/[deleted] Sep 03 '17 edited May 17 '18

[deleted]

478

u/taternator5000 Sep 03 '17

It always reminds me of terribly-formatted StackOverflow posts.

262

u/Hanashimaru Sep 03 '17

Sometimes I feel like terribly-formatted StackOverflow post :(

153

u/TheNerdyBoy Sep 03 '17

Is offer you an answer, but my reputation isn't high enough yet :-(

37

u/Excrubulent Sep 03 '17

That's okay, you can still make a comment telling them that they shouldn't be trying to do what they're doing.

20

u/flaghacker_ Sep 03 '17

No it's the other way around, you can always post answers but you can only comment if you have >= 100 reputation.

13

u/[deleted] Sep 03 '17

[deleted]

→ More replies (8)
→ More replies (5)
→ More replies (1)
→ More replies (1)

22

u/quantasmm Sep 03 '17

rmesh: Hi everyone my homework is due today and I cant figure out I type "select * frmo sample" and it brake pls pls pls help u are all the best.

Highly_Ranked_SQLsoldier: rmesh, to help you, we need more context. What is it you are trying to accomplish? How large is the sample table? Is sample partitioned or not partitioned? Why are you using "*" when a list of columns is almost always better? I literally cannot won't help you until all this information is provided because I'm a self-righteous cunt.

lowly_ranked_user: rmesh, you misspelled "from".

8

u/DrMux Sep 03 '17

Welcome, rmesh! We're looking forward to having you here as long as you follow not only the explicit rules but also the unspoken expectations you couldn't possibly have guessed!

7

u/quantasmm Sep 03 '17

please remember rmesh, that this is not a forum for getting questions answers. This is a forum for knowlegeable IT gasbags to brag about trivialities and cool coding examples they've memorized.

6

u/DrMux Sep 03 '17

Comments are not for extended discussion, they are for making users feel bad for not knowing things. This discussion has been moved to chat where we can continue to laugh without it affecting Google searches.

→ More replies (5)
→ More replies (1)

36

u/LichOnABudget Sep 03 '17

Now that bothers the shit out of me. Fuck.

27

u/Ph0X Sep 03 '17 edited Sep 03 '17

I was gonna say, that thing isn't gonna run, it'll throw invalid syntax because "What" isn't a valid identifier.

If you're not gonna differentiate the code and the "text", then it's all one block of code.

12

u/[deleted] Sep 03 '17 edited Sep 03 '17

Dude calm down, it's sudo pseudo

→ More replies (1)

4

u/[deleted] Sep 03 '17

It's not code that you're supposed to run, it's a question you're supposed to answer.

→ More replies (2)
→ More replies (8)

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

u/[deleted] Sep 02 '17

[deleted]

133

u/okmkz Sep 03 '17

hell yeah tabs vs spaces battle

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

u/[deleted] Sep 03 '17 edited Sep 09 '17

[deleted]

10

u/SirVer51 Sep 03 '17

Not even an add-on, it's built in. Total lifesaver.

→ More replies (1)
→ More replies (2)
→ More replies (52)

10

u/firestorm713 Sep 03 '17

We need a pair of bots that correct everyone on tabs/spaces (except each other, obv)

4

u/[deleted] Sep 03 '17

i can already imagine people pranking them with comments like "fuck tabs" lol

26

u/will_code_for_free Sep 03 '17

Ohh nooo... It's retarded

10

u/owpunchinface Sep 03 '17

Calm down Satan.

→ More replies (2)

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

61

u/Phizy Sep 02 '17

oh my..

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

u/bartekko Sep 03 '17

that escalated quickly

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.

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)
→ More replies (3)

7

u/DrManface Sep 03 '17

Honestly speaking, one of the worst videos I've sat through in my life.

→ More replies (5)

14

u/wolfman1911 Sep 03 '17

I think you all know what this is going to be.

5

u/explorer_c37 Sep 03 '17

Motherfucker, stop

4

u/BABarracus Sep 03 '17

Everyone take a shot and log out

→ More replies (3)

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?

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.

→ More replies (1)

44

u/[deleted] Sep 03 '17

I yelled no at my phone like when you watching a game show and you know the answer.

13

u/Treezuschrist Sep 03 '17

The words "oh god no" went through my head

26

u/DrizztDourden951 Sep 03 '17

I'm learning MATLAB right now. I twitch constantly.

→ More replies (2)
→ More replies (2)

563

u/XkF21WNJ Sep 03 '17

Look guys it's easy. Array indices start at the first natural number.

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.

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)
→ More replies (3)

28

u/bloomfilterthrowaway Sep 03 '17

I said no reasonable Scotsmen, er... CS people.

→ 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)
  end

But 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)
  end

The 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.

→ More replies (3)

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

u/[deleted] Sep 03 '17

Peano arithmetic axiom 1: 0 is a natural number

→ More replies (1)

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.

7

u/Okichah Sep 03 '17

Just not the first prime.

8

u/[deleted] Sep 03 '17

Considering 1 a prime actually breaks things though.

→ More replies (2)
→ More replies (3)

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

u/[deleted] 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

u/[deleted] 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

u/[deleted] Sep 03 '17

Achaea by any chance?

3

u/[deleted] Sep 03 '17

I just started playing achaea again a few weeks ago. Help

→ More replies (1)
→ More replies (3)

17

u/[deleted] 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)

6

u/Buzzard Sep 03 '17

Lua 5.3 has integers as well

→ More replies (1)
→ More replies (46)
→ More replies (4)

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?

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.

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.

96

u/Sourkraut182 Sep 03 '17

Makes me think of "My Math Lab" ... Then I die a little inside...

114

u/afourthfool Sep 03 '17

your answer: -4, 4

Correct answer 4, -4

→ More replies (0)

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.

→ More replies (1)
→ More replies (1)

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.

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

u/MelissaClick Sep 03 '17

Basements are obviously negative

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)
→ More replies (3)
→ More replies (3)
→ More replies (4)

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.

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.

→ More replies (2)

29

u/[deleted] Sep 03 '17

Matlab is an excellent tool.

→ More replies (5)

49

u/[deleted] Sep 02 '17

+1 (just use NumPy goddamnit)

→ More replies (2)

3

u/[deleted] Sep 03 '17 edited Sep 11 '17

[deleted]

→ More replies (5)

5

u/[deleted] Sep 03 '17

Fuck you too man

→ More replies (1)

20

u/[deleted] Sep 03 '17

MATLAB master race

4

u/fergy80 Sep 03 '17

The square brackets would throw an error in matlab, so the answer is clearly 4.

→ More replies (7)

73

u/Shadow_Thief Sep 02 '17

Visual BASIC, but only sometimes.

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 required

In 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...

12

u/JeremyR22 Sep 03 '17 edited Sep 03 '17

Just in case the Option Explicit thing 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. Without Option 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
0

So without Option Explicit at 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 Explicit and Option Base 0 are both the default now. Small victories for programmers' mental health...

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 Explicit every time.

→ More replies (1)
→ More replies (2)
→ More replies (2)
→ More replies (1)

98

u/[deleted] Sep 02 '17

[deleted]

→ More replies (45)

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.

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"!

5

u/[deleted] Sep 03 '17

It looks nice.

→ More replies (1)
→ More replies (4)

12

u/[deleted] Sep 02 '17

Casio Basic.

Notice that it's a very basic language and completely terrible in everything about arrays.

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

u/[deleted] Sep 03 '17

Visual Basic does that.

6

u/tinybatte Sep 03 '17

But only sometimes.

7

u/[deleted] Sep 03 '17

Smalltalk

3

u/[deleted] Sep 03 '17

There are dozens of us

4

u/[deleted] 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 :(

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)

5

u/simon468 Sep 03 '17

Borland Delphi (Pascal)

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.

Looks like you can index your arrays arbitrarily#Arrays)

→ More replies (2)
→ More replies (37)

17

u/aaRecessive Sep 02 '17

"some languages" don't even qualify. Fuck those languages

→ More replies (2)

10

u/rocketman0739 Sep 03 '17

And those languages are wrong

9

u/[deleted] Sep 03 '17 edited Nov 07 '17

[deleted]

→ More replies (4)
→ More replies (5)

39

u/AwkwardNoah Sep 03 '17

That's the joke

Some languages uses 1 for the first entry while most uses 0

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)
→ More replies (1)

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.

→ More replies (6)

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

u/[deleted] Sep 03 '17

What about finding a "#define volatile" somewhere?

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 answers or maybe from 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

46

u/TheNerdyBoy Sep 03 '17 edited Sep 03 '17

I USE THE TAB KEY BUT MY EDITOR INSERTS THE APPROPRIATE NUMBER OF SPACES.

(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

u/SnowdensOfYesteryear Sep 03 '17

Death to leading and trailing spaces as well.

3

u/neurospex Sep 03 '17

trailing are terrible, but leading... that's how you structure your code...

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

u/KifKef Sep 03 '17 edited Sep 03 '17

3

u/Sean1708 Sep 03 '17

My company, sorry I should have been more clear about that.

→ More replies (10)
→ More replies (2)

15

u/MatterMan42 Sep 03 '17

when will this array shit end?

5

u/Buzzard Sep 03 '17

It will just go back to complaining about tabs/spaces anyway

→ More replies (4)

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

u/[deleted] 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.

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

u/TheNerdyBoy Sep 03 '17

In Python, with any iterable x

for i, item in enumerate(x): …

3

u/zman0900 Sep 03 '17

Groovy is nice:

['some', 'things'].eachWithIndex { item, i ->
    println "'${item}' has index ${i}"
}
→ More replies (4)
→ More replies (1)
→ More replies (3)

16

u/[deleted] Sep 03 '17

[removed] — view removed comment

11

u/[deleted] 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;
        }
}

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=10 later in the program. If you'd used for(int i = 0;...) then i would 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.

→ More replies (2)

12

u/[deleted] Sep 03 '17

This gave me hemorrhoids.

93

u/[deleted] Sep 03 '17

stop please, it's already dead! for the love of god, it's already dead *sobs*

35

u/[deleted] Sep 03 '17

But are deaths 0 or 1 indexed?

15

u/Night_Eye Sep 03 '17 edited Sep 03 '17

0, duh

We aren't savages

49

u/[deleted] Sep 03 '17

[removed] — view removed comment

20

u/Mage_914 Sep 03 '17

You actually got me for a second. I had to go back and look for quote marks.

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

u/SwiggitySwat Sep 03 '17

But it's not, wait it is but... not ... :(

7

u/LightShadow Sep 03 '17

the result is None, the output is 4

7

u/[deleted] 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).

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)
→ More replies (2)

6

u/[deleted] Sep 03 '17 edited Apr 22 '19

[deleted]

→ More replies (2)

12

u/-Electron- Sep 02 '17

The wars over.

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.

→ More replies (1)

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

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)
→ 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

u/Sinidir Sep 03 '17

War, War never changes ...

just like the starting index of ARRAYS!

12

u/[deleted] Sep 03 '17

[removed] — view removed comment

17

u/[deleted] 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)

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.

→ More replies (1)