←back to thread

498 points azhenley | 4 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 #
1. kragen ◴[] No.45768136[source]
Rust is not very suitable for functional programming because it is aggressively non-garbage-collected. Any time Rustaceans want to do the kind of immutable DAG thing that gives functional languages so much power, they seem to end up either taking the huge performance and concurrency hit of fine-grained reference counting, or they just stick all their nodes in a big array.
replies(1): >>45768441 #
2. tayo42 ◴[] No.45768441[source]
Using a big array has good performance though?
replies(2): >>45768613 #>>45770186 #
3. kragen ◴[] No.45768613[source]
Computer memory is already a big array. Probably what you are thinking of is that processing array items sequentially is a lot faster than following pointers, but in the cases I'm talking about, you end up using array indices instead of pointers, which isn't much faster.
4. gf000 ◴[] No.45770186[source]
Yeah, but now logic bugs can cause memory leaks, doing use-after-frees, etc, without any kind of tooling to prevent it (nothing like valgrind to catch them). Sure, they won't crash the program, but sending money from a wrong account is worse than a segfault, imo.