> 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…
Const by default is not functional programming.
John Carmack on mutable variables
31–40 of 663 posts
Re: John Carmack on mutable variables
#32Earlier quoted context omitted.
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)…
> come with the baggage of foreign looking syntax Maybe they're right about the syntax too though? :)
Re: John Carmack on mutable variables
#33Proposing making immutable by default in C or C++ doesn't make sense due to backwards compatibility reasons. New languages like Rust have easier time making better choices with immutable by default.
https://github.com/hsutter/cppfront/wiki/Design-note%3A-cons...
Re: John Carmack on mutable variables
#34Why loops specifically? Why not conditionals? A lot of code needs to assemble a result set based on if/then or switch statements. Maybe you could add those in each step of a chain of inline functions, but what if you need to skip some of that logic in certain cases? It's often much more readable to start off with a null result and put your (relatively functional) code inside if/then blocks to clearly show different l…
if cond:
X = “yes”
else:
X = “no”
X is only ever assigned once, it’s actually still purely functional. And in Rust or Lisp or other expression languages, you can do stuff like this: let X = if cond { “yes” } else { “no” };
That’s a lot nicer than a trinary operator!Re: John Carmack on mutable variables
#35Re: John Carmack on mutable variables
#36Re: John Carmack on mutable variables
#37> I wish it was the default, and mutable was a keyword. I wish the IDE would simply provide a small clue, visible but graphically unobtrusive, that it was mutated . In fact, I end up wishing this about almost every language feature that passes my mind. For example, I don't need to choose whether I can or can't append to a list; just make it unappendable if you can prove I don't append. I don't care if it's a map, lis…
Re: John Carmack on mutable variables
#38Kinda curious on what jblow would say about this.
Re: John Carmack on mutable variables
#39[flagged]
Re: John Carmack on mutable variables
#40Proposing making immutable by default in C or C++ doesn't make sense due to backwards compatibility reasons. New languages like Rust have easier time making better choices with immutable by default.
cpp2/cfront could plausibly do this, right? Except he doesn't want to: https://github.com/hsutter/cppfront/wiki/Design-note%3A-cons...