Live data from Hacker News

Is your programming language unreasonable? (2015)

fsharpforfunandprofit.com

31–40 of 138 posts

Re: Is your programming language unreasonable? (2015)

#31
post #15
post #4

> " 4. Objects must always be initialized to a valid state. Not doing so is a compile-time error. " So this essentially means there can never be a NULL object assigned to anything... how is this possible? is it avoided by throwing exceptions instead of returning NULL?

Not only that, it implies that there must be a valid null-state for every type, which is also a bad idea.

No, it implies that you can use your type system to surface the fact that a variable may have no values.

Re: Is your programming language unreasonable? (2015)

#32

"Objects containing the same values should be equal by default." No. This breaks down as soon as you have references to other objects in your objects. If you compare by reference, you probably don't get what you want. If you compare by value, you need to go arbitrarily deep, which is not a sane default, because of possible reference cycles. You need a distinction between objects and value types. C# has that (record t…

The whole point is that equality should have nothing to do with comparing references.

Your comment is just making the author's point. References, cycles, mutable state these just make it harder to reason about your code.

And a nice petty little zing at the end for good measure. Good job.

Re: Is your programming language unreasonable? (2015)

#33

"Objects containing the same values should be equal by default." No. This breaks down as soon as you have references to other objects in your objects. If you compare by reference, you probably don't get what you want. If you compare by value, you need to go arbitrarily deep, which is not a sane default, because of possible reference cycles. You need a distinction between objects and value types. C# has that (record t…

> The real world is all about mutable state. At some point, you need to take the training wheels off.

Funny enough, I think the opposite is true. For example, if you have a moving point in the real world, there is never a point where only the x coordinate is mutated, yet you have that in your mutating code.

Re: Is your programming language unreasonable? (2015)

#34
post #13

> I don’t care what my language will let me do, I care more about what my language won’t let me do. I think this is the best summary of the article. In short, please protect me from my own stupidity and/or laziness.

I like how this could be taken as an endorsement or criticism of the article, depending on the hubris of the reader

[deleted]

Re: Is your programming language unreasonable? (2015)

#35

"Objects containing the same values should be equal by default." No. This breaks down as soon as you have references to other objects in your objects. If you compare by reference, you probably don't get what you want. If you compare by value, you need to go arbitrarily deep, which is not a sane default, because of possible reference cycles. You need a distinction between objects and value types. C# has that (record t…

Accountants do not use erasers.

Mutating variables in-place is the training wheels.

Got a bank account? Want me to transfer money by increasing this account and decreasing that account?

But perhaps that's too small an example. What about a large, distributed system?

Both Paxos and Raft are recipes for clusters of machines to agree on immutable sequences of values.

Re: Is your programming language unreasonable? (2015)

#36
post #9

Earlier quoted context omitted.

If you forget everything you ever learned about programming, and then I ask you for an integer, you're never in a million years going to reply "null"; the existence of "null" is something you had to learn. A language could simply not have a concept of "null". Even an OO language could have no concept of "null". In practice, it's useful to be able to answer "I'm sorry, Dave, I can't do that". Some languages do that by…

Null is just an invalid pointer target that you can verify easely. It is just abi convenience and removes the need for a flag. On the other hand I unironicly write goto:s and use globals as much as a please (think GNU Bison/Flex) so who I am to judge.

I don't really view that as being relevant. F# compiles `Option.None` down to a null under the covers; what matters is that the type system is null-aware.

Re: Is your programming language unreasonable? (2015)

#37
post #23
post #15

Earlier quoted context omitted.

Not only that, it implies that there must be a valid null-state for every type, which is also a bad idea.

I'm not entirely sure what you're getting at here. Are you saying the author is arguing a call like new Customer() should return something valid? I think the FP way would be to disallow constructor overloads with no arguments, as really, there's no reasonable thing to be done here. If you don't have all the necessary information to initialize a customer yet, you don't get to initialize one, and you pass around a part…

> Admittedly, this prevents you from accessing name until you provide an address, but I don't think there are many valid use cases where you want to access data before the Customer value is corrrectly initialized. I'd consider this a code smell to be refactored.

If you really needed to do that you could just define a partial customer with no address field and pass are that around.

Re: Is your programming language unreasonable? (2015)

#38
A bit of a tangent, but I tried F# recently to make a small gamedev framework. I absolutely adored the language at first. Loved the syntax. loved the type definitions and domain modeling. I felt maybe, this is it, this is the language for me. Never felt that way about a language since the last time I wrote something in Crystal.

Then came the part where I needed to work with list of records and realized that something as basic as that which I take for granted in other languages, is a monstrously complicated concept in f#. I got introduced to the shady world of Lenses, tried my hand for a bit and decided to get out. Lenses are not for me.

I can't believe that a language makes updating records so difficult. F# is my first functional language and while I expected some friction in doing such stuff in a functional language, I never expected so much work around something so trivial. But is does helps me understand why people don't use F# for things like gamedev.

Anyway TLDR; love the language. Wish that it will make concepts like Lens much easier to use in the language

Re: Is your programming language unreasonable? (2015)

#39
The article goes through a series of examples to show motivations for the following:

1. Variables should not be allowed to change their type.

2. Objects containing the same values should be equal by default.

3. Comparing objects of different types is a compile-time error.

4. Objects must always be initialized to a valid state. Not doing so is a compile-time error.

5. Once created, objects and collections must be immutable.

6. No nulls allowed.

7. Missing data or errors must be made explicit in the function signature.

The idea being that each feature or constraint _enables_ you to reason and predict more about a program than you could otherwise.

I encourage anyone interested in these ideas to play around with F# or a similar language and get a feeling for how they influence your code. If you've mastered one paradigm such as OO one of the best ways to find holes in your mental models is to try and find another point of view to look at the same problems. Even if you keep writing most of your code like you do today, in the language you do today, it can still be beneficial.

Re: Is your programming language unreasonable? (2015)

#40

I lost the line of reasoning (or perhaps the author did) at the second example. If I have 2 InputStream objects, nevermind equality. It just doesn't apply here. I don't even want `a.Equals(b)` to be considered valid code in the first place. Having __any__ default behaviour here is a lot like the permissiveness that is bashed in example 1 (a trifecta of unexpected variable scoping rules, the ability to re-type variabl…

Note that F# has the `[ ]` attribute for exactly that sort of case.

That's the wrong default though.

There is no reason to assume equality is a sensible concept, so objects should not even be equatable by default, and you could have an attribute which gives them structural equality (with a third option of a full-blown custom equality if necessary) as e.g. Haskell or Rust handle it.

Post reply on HN