#] WTF is wrong with code?
No, I'm serious. Some shit really does not make sense.
Note: I was inspired to make this page by
this page.
Note: These code blocks are typed by hand. The interpreter on your machine will most likely look different than what is shown. Additionally, terminal based interpreters do not have syntax highlighting. I added that
here so people who don't code have an idea of what is what kinda.
#] JavaScript
Let's talk about JavaScript.
Some background is necessary.
[] is an array, a list.
{} is an object, could be literally anything.
NaN is "Not a number"
#] Equals
So, lets talk about this:
==. This makes no sense. In every single language, it means "is it equal?", but in JS, this is calculated as a percentage for some reason. I'm serious. In Python it's either
equal or not equal. In JS, however, it's kinda equal? I don't know how equal it is but it must be between 0% and 100% equal. If it isn't
not equal [0%, thus isn't equal], then it must be equal [anywhere from 1% to
100%, thus is equal].
// JavaScript
>>> 1 == "1"
true
I just want to see how equal things can get, though.
// JavaScript
>>> 1 === "1"
false
I see, now it can tell me if it's equal or not equal. So, that means the more equal signs I add, the more the more equal it can check, right?
// JavaScript
>>> 1 ==== "1"
SyntaxError
Of course not.
Strings are not integers, and should not be treated as such. This is silly.
#] Lists
In all languages, you can make two lists by appending the contents of one list to another using the
+ operator.
# Python
>>> [1, 2, 3] + [4,
5, 6]
[1, 2, 3, 4, 5,
6]
>>> [] + []
[]
Makes sense, right? Add one list to another to make a larger list, like we do in real life. Let's see what happens in JS.
// JavaScript
>>> [] + []
""
OF COURSE FUCKING NOT.
Let's be different. Subtracting, however, shouldn't work. What would you remove, where? JavaScript has a solution.
// JavaScript
>>> [] - []
0
#] Objects
This should be quite simple. Let's see what happens when we add an object and a list together. They are completely incompatible data types, so it should throw a TypeError or something like that.
// JavaScript
>>> [] + {}
"[object Object]"
Well, if that works, then let's try reversing it because that's how addition works afterall. And of course, we get the same thing.
// JavaScript
>>> {} + []
0
>>> {} - []
-0
Makes sense to me. I love negative zero. Let's try adding two objects.
// JavaScript
>>> {} + {}
NaN
Not a number. I see.
#] Strings
A string is text. Like "hi". Most languages do not automatically convert datatypes without explicit instruction. JavaScript is one of those exceptions. So, adding will concatonate, or append to the end of the string.
// JavaScript
>>> 12 + "34"
"1234"
So, let's try subtracting. Shouldn't work because strings aren't numbers, right?
// JavaScript
>>> 12 - "34"
-22
Well of course I was wrong. When did JS ever make sense?
#] Python
Python is a very sane language, relatively speaking to JavaScript of course. Python accepts inputs directly from the console. Let's input a number.
# Python
>>> int(input("Input a number ] "))
# Convert to an integer [no decimals]
Input a number ] 2.5
ValueError
Nice, I cannot input a decimal and expect it to come out as an integer. JavaScript, the insane language as described previously, allows this just fine, probably because strings are also numbers too.
#] Ruby
Let's talk about Ruby.
#] Assigning variables
If a variable is not defined, it should throw an error.
# Ruby
>>> a
NameError
>>> b
NameError
Great, all works as expected. Let's try assigning a variable with an unknown variable. This shouldn't work either.
# Ruby
>>> a = b
NameError
Nice, but now let's try assigning an undefined variable to itself.
# Ruby
>>> a = a
nil
Um,
a is
nil now I guess.
#] Funky types.
nil is
null, or literally nothing. Absolutely no data is stored. Therefore,
nil should always be
nil.
# Ruby
>>> nil
nil
I have no idea what it means, but lets add a question mark
# Ruby
>>> nil?
false