News for hackers. Stuff that matters.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by lelanthran on Monday February 19, 2024 @04:47AM (#39427811)
> The fact that you need to use entire words to denote syntax makes it much harder for your brain to parse things : Instead of immediately seeing "this is code structure" and "this is actual code", you need to actually read the words to make that distinction. It is very counter-productive and a bad design solution, imo.

While I agree that it gets slightly tedious to read daily, I have to say that there is no language other than pascal that lets me come back to the language after 3 years and instantly be able to read it with no problems.

I don't know if any other language where this is possible.

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by rlawson on Monday February 19, 2024 @08:12AM (#39429375)
Agree! I also find Pascal very soothing to write. Yes it's a little more verbose than C but it makes you think ahead and stay organized.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by zozbot234 on Monday February 19, 2024 @09:23AM (#39430012)
Many people have the same experience writing Rust. And they have plenty of time to relax while the program compiles.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by LorenzoGood on Tuesday February 20, 2024 @05:10PM (#39447665)
Relevant Xkcd: https://xkcd.com/303/
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by tux3 on Monday February 19, 2024 @05:18AM (#39427979)
While I'm not the world's #1 Golang fan, this is something that they have. They took a lot of complexity out of the language, so any code you look at will seem very simple & readable. There's not a lot of magic syntactic sugar, you just write things down the simple verbose way.

The flip side of that coin is you have to reimplement a lot of things yourself, so any essential complexity that the language doesn't handle for you is pushed on you to re-implement in your codebase.

Python's decent at this too. At least the simple Python people use in small scripts. It's almost pseudocode, as long as no one tries and overengineers it.

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by archargelod on Monday February 19, 2024 @08:26PM (#39436972)
> Python's decent at this too. It's almost pseudocode. Nim has Python-like syntax. But, I find it even easier to read/parse at a glance than Python.

Also, I hate that in languages with dynamic typing you have to read whole function to understand what type of arguments it takes and what is the return type. Nim is statically-typed, so all the types are properly declared.

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by wizzwizz4 on Monday February 19, 2024 @05:50AM (#39428291)
In my experience, Python, C and JavaScript* all have this property; whereas I have to relearn Pascal, Haskell, sh and (to an extent) Rust every time I go away from them for a bit. I think this is more a property of you or I than of particular languages.

*: excluding `for (… of …)` and `for (… in …)` – I can never remember which is which. `for (… of …)` is the one you can use with Arrays and other iterables.

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by lelanthran on Monday February 19, 2024 @06:31AM (#39428638)
> *: excluding `for (… of …)` and `for (… in …)`

There's more that will trip you up in JS if you leave it for too long. Off the top of my head:

1. Which function definition (`function` or `=>`) do I need to use in order to make the `this` keyword point at the correct object in an event handler/anonymous function/foreach parameter?

2. I see code with both `!==` and `!=` - what is the significance of using both?

3. Long chains of `filter` and `map`.

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by jameshart on Monday February 19, 2024 @07:47AM (#39429170)
Long chains of filter and map are common in any language - they may have better chaining syntaxes, but since mapreduce can basically implement any collection operation you can imagine, filter and map chains are going to crop up.

With its tuple, object, and destructuring syntaxes JS actually ends up with some of the most readable mapreduce code of mainstream C-derived languages (it’s soooo much worse in Java).

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by fzzzy on Monday February 19, 2024 @08:12AM (#39429372)
Just always use !==. != will automatically cast and !== won't, therefore "1" != 1 is false and "1" !== 1 is true.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by hellcow on Monday February 19, 2024 @09:17AM (#39429968)
Unless you’re testing if something is null or undefined, in which case a single “x != null” handles it.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by fzzzy on Monday February 19, 2024 @11:11AM (#39431362)
Sure. I usually just use !x for that.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by SamBam on Tuesday February 20, 2024 @10:28AM (#39442432)
That doesn't test if it's null or undefined, that just tests if it's not falsy.

x = 0; !x → true

y = ""; !y → true

z = null; !z → true

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by wizzwizz4 on Monday February 19, 2024 @02:10PM (#39433466)
1. `function` gives you a new `this`, whereas `=>` closes over the `this` from the parent scope. Which to use depends on what you want. (Full disclosure: I would've had to think for a bit whether the syntax was `->` or `=>` – though I'd probably guess `=>` because `->` means something in C.)

2. `!==` is strict comparison, and `!=` tries to do incomprehensible magick to munge incomparable types together. I still know some of the rules (array to string sticks in my mind), but I doubt many people know all of them. There's almost never a good reason to use `!=`, outside `elem.value != my_integer`. (Though `NaN !== NaN`, so you need to watch out for that: since equality is defined recursively on objects I'm pretty sure this is infectious.)

3. The length of the chain is easy (though, iirc there are performance implications since it's not lazy). The hard part is the fact that map callbacks can take one, two or three arguments, so stuff like `["123", "456", "10", "1234"].map(parseInt)` will behave unexpectedly. (Something like `[123, undefined, 2, 5]`, though I might be thinking of PHP.) Not sure whether `Array.prototype.filter` has similar gotchas.

That's off the top of my head. I haven't seriously used JavaScript since the ES5 times, but JavaScript's a very… memorable… language. (I can't even remember hello world in Pascal.)

Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by Jean-Papoulos on Tuesday February 20, 2024 @10:12AM (#39442218)
I just tried make a ".any" generic function for arrays, and by god :

Most languages : myArray.any((e) => true);

Delphi : AClass.any<Type>(myArray, function (e) : Boolean begin Exit(True); end);

The readability is through the roof, lol.