←back to thread

498 points azhenley | 2 comments | | HN request time: 0s | source
Show context
munchler ◴[] No.45767832[source]
> Making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword.

It's funny how functional programming is slowly becoming the best practice for modern code (pure functions, no side-effects), yet functional programming languages are still considered fringe tech for some reason.

If you want a language where const is the default and mutable is a keyword, try F# for starters. I switched and never looked back.

replies(19): >>45767880 #>>45767882 #>>45767891 #>>45767892 #>>45767898 #>>45767926 #>>45767975 #>>45767989 #>>45768118 #>>45768188 #>>45768230 #>>45769840 #>>45769875 #>>45770104 #>>45770306 #>>45771134 #>>45771926 #>>45772136 #>>45775848 #
tasn ◴[] No.45767898[source]
Functional programming languages (almost always?) come with the baggage of foreign looking syntax. Additionally, imperative is easier in some situations, so having that escape hatch is great.

I think that's why we're seeing a lot of what you're describing. E.g. with Rust you end up writing mostly functional code with a bit of imperative mixed in.

Additional, most software is not pure (human input, disk, network, etc), so a pure first approach ends up being weird for many people.

At least based on my experience.

replies(7): >>45767931 #>>45768098 #>>45768136 #>>45769309 #>>45770165 #>>45771129 #>>45772143 #
rao-v ◴[] No.45769309[source]
Exactly this! I’d love a modern C++ like syntax with the expressiveness of python and a mostly functional approach.

C# is not that far I suppose from what I want

replies(2): >>45769657 #>>45772200 #
tjk ◴[] No.45769657[source]
Everybody's mileage will vary, but I find contemporary C# to be an impressively well rounded language and ecosystem. It's wonderfully boring, in the most positive sense of the word.
replies(1): >>45769893 #
LogicHound ◴[] No.45769893[source]
I can't stand modern C#. They've bung in a bunch of new keywords and features that are of dubious benefit every release.
replies(1): >>45770079 #
mrsmrtss ◴[] No.45770079[source]
I'm interested what are those new keywords and features that are of dubious benefit?
replies(1): >>45770216 #
LogicHound ◴[] No.45770216{3}[source]
There is a huge amount of syntactic sugar that has been added over the years that doesn't do whole lot IMO. It is often imported from other languages (usually JavaScript and/or Python).

e.g. Just a very simple example to illustrate the point

    if (customer != null)
    {
        customer.Order = GetCurrentOrder();
    }
vs

    if (customer is not null)
    {
        customer.Order = GetCurrentOrder();
    }
Is there really any benefit in adding "is/is not"? I would argue no. So I categorise that as being of "dubious benefit" and there are many similar small features, keywords etc. that get added each release where they might save a few lines of code somewhere but I've never seem them used that often.
replies(2): >>45770743 #>>45772955 #
1. 1718627440 ◴[] No.45772955{4}[source]
In Python '==' and 'is' are not the same thing. '==' checks for equality, 'is' for identity.
replies(1): >>45773665 #
2. LogicHound ◴[] No.45773665[source]
I am aware. I probably should have said "inspired".