wat
I recently rewatched
this talk (wat)
and it is just always funny every time I watch it. It is probably my favorite talk of all time, and I highly recommend watching it yourself if
you know anything about programming.
It's made me think about programming languages this last time, though. It pokes a lot of fun at javascript, and it's not really something
I quite understood the gravity of until I started using it for this website. Like, nothing is ever the right ♥♥♥♥♥♥ type in javascript, and it is
so reluctant to throw you an error, even when it should. That being said, some of the silliness displayed in the talk don't exist anymore
(object + any object does not return a number anymore, thankfully). Still, I actually kind of dislike javascript despite how much less egregious
it has become over time.
I figure that I should take the time to discuss some other languages as well. I hold the belief that most programming languages are
at least 90% similar, and no programming language has sufficiently challenged this belief for me thus far (besides matlab, which I refuse to acknowledge exists).
Despite that, I think that some languages do have some notable (for both the worse and the better) characteristics and oddities.
Lua
Lua is a bit of a strange language, and you only really see it in certain contexts. It's a language that integrates really well into C applications,
so it's often used for modding in games written in C / C++. It's probably the most unique language that I interact with.
Some interesting characteristics:
- Comments are written with two dashes, "--". Multiple line comments are done with "--[[" and "]]--". I don't think there's another language that does comments exactly like this.
- Starting and closing functions and if statements is done with "then" & "end" rather than "{" & "}". Parantheses aren't required in if, while, or for statements. Lua is similar to bash in this way.
- There is no 'continue' keyword, though 'goto' still exists so this isn't super impactful.
- Arrays are 1-indexed. I think that this is bad at least because it is conflictory with C arrays, which are 0-indexed.
- Anonymous functions are completely hassle-free. To illustrate:
function doSomething(a, b)
--some code
end
Variable1 = doSomething --no parantheses used assigns the function
Variable1(0, 4) --uses the function with (a, b) = (0, 4)
Variable2 = function() print("abc") end --inline anonymous function
- Arrays are actually called tables, which are basically Object -> Object maps instead, but without the hassle associated with them in other languages. They can of course act as arrays.
- Concatenating strings has its own operator, "..". This is such a good idea and I think this should be standard in more languages, as it avoids issues with the arithmetic + operator. PHP also kind of has this.
- Variables can be assigned as arbitrary objects, basically. What I mean is that you can do this:
Variable1 = {x = -1, y = -1, z = 4}
print(Variable1.x) --prints -1
All in all, I don't really like dynamically typed languages, but I think that Lua at least takes full advantage of it.
Tables and objects are convenient in the language because it is dynamically typed, so it's not something you could have in a C derivative or Java or whatever.
Relatedly, I've seen a naming convention for dynamically typed variables that prefixes the variable name with its type
identifier and an underscore, i.e., an integer variable orginally named "num" -> "i_num". Maybe this is common practice but it seems like a good idea.
Bend
Bend is a language that is fundamentally designed to support multi-threaded code execution. It lets you run the same code on a single CPU core, on multiple CPU cores, or on the GPU. It's a really unique idea. This exists in other languages, but you don't have to deal with the specifics in Bend (ofc you still have to write code that is parallelizable to begin with). Last time I used it, it was not very performant which I think was probably the result of a primitive compiler with few optimizations, but I don't know. I don't have much else to say about this language though besides that it is a really cool idea.
C#
C# is very similar to Java in a lot of ways. The language was actually designed to mimic Java (it was a copycat created by Microsoft after losing
a lawsuit to Sun about altering the Java specification). Supposedly a converter for Java -> C# code existed back in the day, though this probably
is not much of a realistic option anymore. When I read about all of this the first time, it really explained a lot because the languages always felt
very similar to me.
C# is also a bit strange to me because of how common a multitude of its versions are. For instance, both netstandard2.0 and netstandard2.1 exist
and are used, and so are net(x.y) versions (two categories + their respective versioning). I've had the displeasure of integrating C# libraries that are not built for the (older) version
that my main project used, which, in my case at least, required untangling some really unholy object oriented shenanigans.
I suppose Java is similar in this way too, with lots of Java stuff still using Java 8.0, which is more than a decade old at this point.
Alright, unstructured list now:
- Goto keyword actually exists unlike Java. I don't think goto is that bad if used sparingly, so this is nice.
- Package management in this language has been a pain in the ♥♥♥ in my experience, though perhaps this is just me.
- It retains some lower-level stuff from C, I guess. It is sometimes useful. Only time I've ever used this feature is to directly compare equality of floats bit-by-bit (done by interpeting float data as int then comparing).
Languages with Custom Operators
In theme with the javascript shenanigans that the wat talk discusses, I find the idea of custom operators to be interesting because it would
allow us to meaningfully define stuff instead of just using hidden generic toString() casts when you don't know what else to do.
For instance, you could actually define object[] + object[] to just append the two arrays together.
Since I haven't ever meaningfully used a language that actually supports this feature, I thought that I might've been onto something.
But no, it exists already. Supposedly, Swift, Haskell, Ada, and more support this feature.
Closing Thoughts
I remember a time where I told another programmer that my main languages were: Lua, C# and Java, and then subsequently got a weird look.
Not that it is that crazy (none of those languages are unpopular), but I never really thought about how my perspective on programming is somewhat different
to some people my age.
Anyways, ♥♥♥♥ javascript. You can choose to interpret the hearts as a sign of love, or as a censor for an expletive.