3 ms·
I wonder about "The canonical approach, Erlang records, are a goofy and oft reviled preprocessor construct with an unwieldy syntax." After writing a bit of Erla
by viraptor 16y ago
I wonder about "The canonical approach, Erlang records, are a goofy and oft reviled preprocessor construct with an unwieldy syntax." After writing a bit of Erlang code, I don't mind records that much. They're not prefect, but I would never call them bad, goofy, etc. They're also used in pretty much every situation where a state in a predefined form is needed (config files, server state, etc.) so that proplists are not needed (no need for dynamic list).
So... what is the complaint about records really?
- rubyrescue 16y agoi agree, you get used to them. but what i don't like about them is that the way you have to specify the record every time you reference the object. so Bar = Foo#foorecord.bar, Baz = Foo#foorecord.baz it feels unnecessarily redundant. Shouldn't we already know Foo is a record of 'fake type' #foorecord? It's like a poor man's type system, and it's ugly. Also, probably more importantly, since they're a compile-time trick you can't use them in the console, which makes experimentation and sometimes debugging harder.
- viraptor 16y ago> Bar = Foo#foorecord.bar, Baz = Foo#foorecord.baz #foorecord{bar=Bar, baz=Baz} = Foo Readability depends on what does your brain process, when you see "=" ;) > since they're a compile-time trick you can't use them in the console Check the `rX` commands from http://www.erlang.org/doc/man/shell.html http://www.erlang.org/doc/man/shell.html You can use the records just like in normal code, but you have to load them explicitly.
- mononcqc 16y agoOne of the problems with records (except the ugly syntax, especially with nested records) as a compile-time construct comes when you need to do hot loading of a module while keeping it running. The transition function using the record can no longer use the '#name{}' construct because the expanded tuple form will not match in both cases and the function will crash. You instead need to expand the old version of the record to avoid the problem. If you forget to, things will go wrong. So yeah, they're ugly and get tricky in some areas of your programs, but they're still essential when you want a data structure with named fields AND pattern matching. You get used to them, but they're still considered a wart to many programmers.