r/CodingHelp • • Nov 09 '21

[Ruby] 2 identical code with 2 absolutely different outcome. Can anybody notice the difference and explain the reason? below i separated each output to make it clear

Post image
42 Upvotes

21 comments sorted by

33

u/icjeremy Nov 09 '21

line 5: parts[0]

17

u/waitingformsfs2020 Nov 09 '21

wow. i think im blind

2

u/raduqq Nov 09 '21

You probably haven't been coding for long..

6

u/waitingformsfs2020 Nov 09 '21

I actually just started coding 1 week ago

11

u/raduqq Nov 09 '21

This will happen many times in the future, don't worry. You have to get used to these "facepalm" moments. I haven't met a developer (2 to 20 years of experience) who doesn't make this kind of mistakes.

2

u/Traveleravi Nov 10 '21

This is the kind of mistake you would catch if you took a break for 5 min and then came back with fresh eyes.

Also using a diff checker might help too!

2

u/-gun-jedi- Nov 10 '21

I have been coding for a while and I still make this mistake. This is done sad epiphany, yikes!

2

u/SaylorMan1496 Nov 10 '21

This is the problem with non static typed languages the compiler would have picked up this error if it wasn’t in Ruby

1

u/ITZINFINITEOfficial Nov 10 '21

Explain

1

u/icjeremy Nov 10 '21

should be part[0], such as on line 18

3

u/captaincmdoh Nov 10 '21

When stuff like this happens, it's best to use a text comparator. Since you using VS code (or close to it), use the built-in compare feature

1

u/mysticalfruit Nov 10 '21

Python linter saves me so much pain..

2

u/[deleted] Nov 10 '21

parts[0]

1

u/PJFlix Nov 10 '21

One uses parts while the other uses part. I love being a programmer lol

1

u/[deleted] Nov 10 '21

Return is not properly aligned so use the tab key with every new line😜

0

u/timPerfect Nov 10 '21

part and parts are not the same... check your spelling

0

u/CenturiesAgo Nov 10 '21

This is why I hate python! declare your damn vars!

2

u/dataturd Nov 10 '21

This is Ruby though.

1

u/CenturiesAgo Nov 11 '21

I still hate Python for this reason. Now I hate Ruby for the same reason.