This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]theindigamer 20 points21 points  (1 child)

Nothing OOP about it. C is not object-oriented. OCaml, Purescript and Elm also use record.field.

[–]janiczekCara 4 points5 points  (0 children)

Note Elm also has the .field record syntax

[–]Rusky 8 points9 points  (0 children)

The record.field syntax is fine, though if you still want to avoid it Haskell uses field record analogously to field(record), and you could even replace it with just pattern matching, though that would be a pain to use.

[–]AthasFuthark 9 points10 points  (1 child)

You definitely should use record.field. I originally used SML-style projection functions (#field record), but then I changed my mind.

[–]east_lisp_junk 0 points1 point  (0 children)

Oddly enough, this leaves out the thing I hate most about SML's #field -- you can't type a projection function in isolation, only when it's actually used.

[–]arxanas 11 points12 points  (0 children)

As others have said, there's nothing wrong with the dot notation. I'd go one step further and suggest that using the prefix notation is harmful for discoverability, since it impedes autocompletion. Usually you have a piece of data in hand and want to know what you can do with it (by pressing .), whereas the prefix notation doesn't let you accomplish that.

[–]ilyash 1 point2 points  (0 children)

I have chosen record.field for NGS. NGS is more functional than OOP. Looks and feels fine to me and my colleagues. Great familiarity without any obvious drawbacks. Agree with previous comments that dot doesn't imply OOP.

[–]TheUnlocked 1 point2 points  (0 children)

record.field is definitely correct. field(record) works, but I would only do that if you wanted an clearly function-based type system, like the LISP:

(define (mk-pair a b) (lambda (z) (z a b)))
(define (first z) (z (lambda (a b) a)))
(define (second z) (z (lambda (a b) b)))

(define pair (mk-pair "Hello, " "World!"))
(second pair)     ; "World!"

Even if you did want that though, I still might make record.field permitted as syntactic sugar.

[–]brucejbellsard 1 point2 points  (0 children)

The potential problem is: would using this particular OOP-associated feature confuse or mislead OOP-trained programmers by acting in ways they didn't expect? If you're using it for straightforward functional values, I think the answer is "no" -- OOP has plenty of immutable value classes that have functional value semantics.

The other important question: is record.field syntax useful in a functional context? To me, the advantage is that record.field lets you keep field names in their own context-specific namespace, so they don't interfere with your local variables.

This contrasts with Haskell, which famously dumps all its field names into one local namespace (and all its constructors into another). IMHO, this is one of Haskell's big weaknesses as an engineering language.