Remix.run Logo
▲ drnick1 2 days ago

All these new languages are unreadable relative to C. If, like me, you like explicit stuff like for (size_t i = 0; i <= n; i++) total += a[i]; all these new languages won't do it.

▲nine_k 2 days ago | parent | next [-]

I don't like this explicitness, because very often it's a lie. In the times of PDP-11 that would compile into a literal counter and literal ADD, DEC, and BNE instructions. Now it will most often compile into some vectorized semi-unrolled form with seven-letter instructions like VPHADDD which add many integers at once, etc.

If I want specific instructions to be run in a specific order, like touching hardware registers, I reach for intrinsics or assembly. If I want an array summed, I prefer to express the intent: total = the_array.sum(); I leave the implementation to the compiler / stdlib.

▲tempest_ 2 days ago | parent [-]

I feel like every time someone tries to tell me how good C is they immediately end up reminding me of https://queue.acm.org/doi/10.1145/3212477.3212479

▲forgotpwd16 2 days ago | parent | prev | next [-]

Funnily, Zig does allow doing it explicitly like that, just need use while rather for:

    var i: usize = 0;
    while (i <= n) : (i += 1) {
        total += a[i];
    }
That said, perhaps Odin, for which simplicity and readability is guiding principle in its design, is more up your alley. In Odin, can be read:

    for i := 0; i <= n; i += 1 {
        total += a[i]
    }
Exactly same style can be used in Go & V (which is/was? quite infamous here in HN). But in all languages, for this example at least, a foreach-like iteration, i.e.

    for x in a {
        total += x
    }
would be preferred.
▲shevy-java 2 days ago | parent | prev | next [-]

You have a point - I find Rust syntax horrible.

C is in some ways minimal, but the pointer-syntax and some more I absolutely dislike. I also found C++ easier to use in some areas, such as:

   cout << "Hey there" << endl;
The equivalent C is simply uglier. Of course C++ failed in other areas big time, but for such simple things like above, I think C++ is better than C. Naturally that cout example is very simplistic, but one can find other examples where C is really quite ugly.
▲atiedebee a day ago | parent | next [-]

puts("Hey there"); is worse than C++ iostream? In my opinion, even printf style strings are better than iostream shenanigans. The main downside of printf is addressed in more modern languages like rust which allow the printed parameters to be embedded in the string so you don't have to keep track of the ordering.

▲dnautics 2 days ago | parent | prev [-]

   cout << "Hey there" << endl;
Yeah but christ as a beginner c++ dev I remember thinking "wtf is << actually doing here?" And tbqf, I'm still not quite sure, 20 years later
▲pasteleft 2 days ago | parent [-]

Of course it is doing a left shift :)

▲raincole 2 days ago | parent | prev | next [-]

I honestly don't think total = a.sum() is any less explicit than for (size_t i = 0; i <= n; i++) total += a[i]. If anything, a.sum() is more explicit as at least it expresses the programmer's intention explicitly. The loop is one more layer between the reader and the writer's intention, without faithfully reflecting what happens on the bare metal. So it's the worst of both worlds.

▲bmandale 2 days ago | parent [-]

A toy example is meant to demonstrate a principle. Toy examples often have alternative ways they can be written, but the concept they are meant to demonstrate requires the whole machinery being employed. Furthermore, how do you think .sum is implemented?

▲elcritch 2 days ago | parent | prev | next [-]

I like doing a mix of either in Nim depending on situation: for i in 0 ..< n: total += a[i]

Sometimes: for x in a: total += x

Sometimes even: foo.foldl(a + b)

▲ 2 days ago | parent | prev | next [-]
[deleted]
▲zzzoom 2 days ago | parent | prev | next [-]

Bad ergonomics in loops is questionable design, but that loop in particular isn't better than total = reduce(a, +, 0).

▲bmandale 2 days ago | parent [-]

> that loop in particular isn't better than total = reduce(a, +, 0).

it is, in fact, better

▲zelphirkalt 2 days ago | parent | prev [-]

It's not very readable. The logic is forced to always use often useless counters and check them, even on the syntax level. I will take any for each mechanism over the loop style. Map, reduce, fold, all better than having to write counters and the check for it.