News for hackers. Stuff that matters.
Re:Why is F# code so robust and reliable? by lispisok on Tuesday September 24, 2024 @12:25AM (#41633098)
Immutability by default contributes just as much if not more
Re:Why is F# code so robust and reliable? by snorremd on Tuesday September 24, 2024 @02:09AM (#41633540)
This is the number one thing that made Clojure work for me despite being dynamically typed. Having confidence that values did not change under my feet after sending them into functions or across thread boundaries was so refreshing. In immutably valued languages even if you technically might be sending a reference to an immutable value type, you can at least practically think about it as pass by value instead.

I never really got into F# or Haskell (more than some tutorials) so can't really comment on the type safety part.

Re:Why is F# code so robust and reliable? by funcDropShadow on Tuesday September 24, 2024 @02:24AM (#41633598)
The value of static typing depends very much on the application domain. In a closed-world application domain where you can be reasonably sure that you know upfront all entities, their attributes, their valid ranges, etc, static typing is extremely valuable. That applies to domains like compilers, system software, embedded systems, and more.

In open-world domains, like business information systems, static typing is often an obstacle to fast adaptation.

Whereas immutability provides value in every domain, unless the performance requirement cannot be met.

Re:Why is F# code so robust and reliable? by bad_user on Tuesday September 24, 2024 @02:38AM (#41633668)
I've heard that argument before, but it never really clicked, and I'm a former fan of dynamic typing.

The application domain is not relevant because you rarely know the domain up-front. Even if the domain is fully known by business stakeholders, it's not known by the application developers, and those domains can be vast. Application development is a constant process of learning the domain and of extending the existing functionality.

This is why all the talk about how LLMs are going to make it possible to replace programmers with people using prompts in English doesn't make much sense. Because the act of programming is primarily one of learning and translating requirements that are initially confusing and context dependent into a precise language. Programming is less about making the computer dance, and more about learning and clarifying requirements.

Static typing helps with refactoring, A LOT!

So when your understanding of the domain changes, YOU WANT static typing because you want to safely change already existing code. You want static typing precisely because it gives you “fast adaptation”.

It's the same argument for why someone would pick Clojure over other dynamic languages. Clojure gives you some guarantees due to the pervasive use of immutability, such that it gives you a clearer view of the API's contract and how you can change it. But statically typed FP goes even further.

I've been involved in projects using dynamic typing (PHP, Perl, Ruby, Python) and with no exception, the code became a mess due to the constant evolution. This is one reason for why we preferred an architecture of microservices because it forces you to think of clear boundaries between services, and then you can just throw away or rebuild services from scratch. Large monoliths are much more feasible in statically typed languages, due to the ability for refactoring. And no, while unit testing is always required, IMO, it isn't the same thing.

Re:Why is F# code so robust and reliable? by funcDropShadow on Tuesday September 24, 2024 @03:01AM (#41633819)
I am a former fan of extreme static typing, think Haskell higher-order type-classes fan. So, yes, I understand the value. But everything you build is very brittle in the face of changing requirement. When requirements seem to change because developers are still learning the domain, that is fine. This churn is unavoidable, true. But, if you have business people tell you, you have to pass some additional information through your system without doing anything to it, and you answer, I have to refactor all my type definitions, then you have some explaining to do.
Re:Why is F# code so robust and reliable? by freilanzer on Tuesday September 24, 2024 @06:31AM (#41635094)
> But everything you build is very brittle in the face of changing requirement.

It's supposed to be 'brittle', in the sense that the compiler verifies your code and if the logic changes, the compiler complains. Everything else is a bug.

> But, if you have business people tell you, you have to pass some additional information through your system without doing anything to it, and you answer, I have to refactor all my type definitions, then you have some explaining to do.

And the explanation is that this is software development, there is no "without doing anything to it". If there's a new requirement I need to adapt the code - take it or leave it, I'm not a wizard. And yes, I have done that already in some form and it was almost always received properly. 'Business people' sometimes have no understanding of software development.

The logic "code changes -> only dynamic typing" isn't valid, in my opinion.

Re:Why is F# code so robust and reliable? by consteval on Tuesday September 24, 2024 @12:16PM (#41638143)
> I have to refactor all my type definitions

The data model did change though. Adding an extra field, even if you don't use it, changes the shape of your data.

Ultimately your data is going to be typed with or without your approval. It's unavoidable, because eventually the data needs to be bits on a disk or on the wire. It's just a matter of how aware of it you want to be.

If you can reasonably keep the shape, and all possible shapes, in your head then fine. But I think you'll find this becomes less feasible as systems grow, and even less feasible in a corporate environment when teams come and go.

Re:Why is F# code so robust and reliable? by randomdata on Tuesday September 24, 2024 @02:43AM (#41633694)
Static typing exists on a gradient. A ounce of static typing is useful to help with the refactoring, as you suggest, but the tradeoffs seem to quickly take over once you go beyond typing basics. Not even the static typing die hards are willing to write line of business applications under complete type system.
Re:Why is F# code so robust and reliable? by bad_user on Tuesday September 24, 2024 @02:48AM (#41633725)
It's a spectrum, of course.

I, for one, prefer more static typing, rather than less. I prefer Scala, OCaml, F#, or Rust. And I've seen some difficult refactorings accomplished in Scala due to its expressive type system, although I can understand why it can be a turnoff.

The downside of having more static typing is a bigger learning curve, so you end up sacrificing horizontal scaling of software development (hiring juniors fast) over vertical scaling (doing more with fewer, more senior people).

Another downside is many times a slower compiler, which changes how you work. Once the code compiles, it may be correct, but then again, you end up doing less interactive development, so you work more in the abstract, instead of interactively playing with the code. I.e., Python's `pdb.set_trace()` is rarely available in static languages. I've always found this difference between dynamic and static languages quite interesting.

Re:Why is F# code so robust and reliable? by randomdata on Tuesday September 24, 2024 @02:54AM (#41633761)
> I, for one, prefer more static typing, rather than less. I prefer Scala, OCaml, F#, or Rust.

Why, then, don't you prefer languages with more static typing? Scala, Ocaml, F#, and Rust are middle of the road at best.

It seems you're echoing that the pragmatic choice for a business application is to stick to typing basics (within some margin of what is considered basic).

Re:Why is F# code so robust and reliable? by bad_user on Tuesday September 24, 2024 @02:58AM (#41633790)
I recognize there are diminishing returns, and also, while I don't want first-tier mainstream languages, at the very least I want second-tier mainstream languages :)

Haskell, for example, is harder to pick, and I wouldn't pick Idris even if I founded my own company.

Re:Why is F# code so robust and reliable? by randomdata on Tuesday September 24, 2024 @03:00AM (#41633807)
Of course you recognize it. It would be impossible for you to not at this point since I pointed it out in my first comment.

I take all of this repeating of what I said is just because it was time for Rust's regularly scheduled advertisement break?

Re:Why is F# code so robust and reliable? by bad_user on Tuesday September 24, 2024 @03:08AM (#41633867)
Indeed, and the same answer was in my first reply to you, read again my first sentence.

And I was pointing out my preferences, thinking we may have an interesting discussion. It appears not.

Cheers mate,

Re:Why is F# code so robust and reliable? by randomdata on Tuesday September 24, 2024 @04:33AM (#41634430)
Indeed, it is true that you started with the repetition right from the get go, but there was an inkling of hope that you came in good faith with substance trying to be added, and not just serving yet another Rust advertisement. But as you now even admit all you have is arbitrary feelings, nothing of possible interest is to be found. Shame.
Re:Why is F# code so robust and reliable? by iLemming on Tuesday September 24, 2024 @02:26PM (#41639503)
Apologies for being pedantic here, but Clojure is too - strongly typed, dynamically typed language. This means types are inherent to the values, not the variables that hold them, providing both safety and flexibility - even though variables don't have fixed types, every value in Clojure has a type.

In contrast, Javascript is weakly typed. Yet, Clojurescript, which compiles to JS, retains Clojure's strong typing principles even in the Javascript (weakly typed) runtime. That (to certain degree) provides benefits that even Typescript cannot.

Typescript's type checking is limited to the program's boundaries and often doesn't cover third-party libraries or runtime values. Typescript relies on static type analysis and type inference to catch type errors during development. Once the code is compiled to JS, all type information is erased, and the JS engine treats all values as dynamic and untyped.

Clojurescript uses type inference, runtime checks, immutable data, and dispatch mechanisms, optimized by its compiler, to achieve strong typing for the code running in the JS engine.

Re:Why is F# code so robust and reliable? by high_na_euv on Tuesday September 24, 2024 @06:10AM (#41634963)
I feel like immutability is overrated as hell

Robust result type benefits give way more

Re:Why is F# code so robust and reliable? by fire_lake on Tuesday September 24, 2024 @06:46AM (#41635161)
Immutability and types go hand in hand. Why? Well with immutability you can do more modelling of your domain as data and then the type system helps you manipulate this data only in valid ways. No type system (I am aware of) can model and check mutable domain models.
Re:Why is F# code so robust and reliable? by AdieuToLogic on Tuesday September 24, 2024 @10:47PM (#41643228)
> I feel like immutability is overrated as hell

Logic defined in terms of immutability can trivially support "undo" and "replay" functionality, amongst other more interesting workflows such as event streaming.

Logic defined in terms of mutable collaborations cannot do so with the same ease.