14 ms·
> Efficient, expressive, elegant let people = [ Person(name: "John", age: 45), Person(name: "Kate", age: 30) ] Verbosity at its finest. Compare wi
by Koshkin 7y ago
> Efficient, expressive, elegant
let people = [
Person(name: "John", age: 45),
Person(name: "Kate", age: 30)
]
Verbosity at its finest. Compare with C++:
Person people[] {
{ “John”, 45 },
{ “Kate”, 30 }
};
- deleted 7y ago[deleted]
- willbw 7y agoI am going to give you the benefit of the doubt that this is a joke.
- staticassertion 7y agoWe reading the same code? The nim code is way simpler. Maybe if you'd used auto (if that's possible - now I understand that auto is out of fashion due to sometimes forcing copies) it'd be closer. `let people = [` vs `Person people[] {` Just for starters...
- agumonkey 7y agoah, syntax debate. * goes back to lisp
- kazinator 7y agoThis is a false comparison because you're really comparing by-order-of-argument initialization/construction ("BOA constructors") versus keyword-value initialization/construction. BOA is more compact, but it's possible to get the arguments wrong, and the type system won't save you if you exchange two arguments of the same type. There is no reminder anywhere that 45 and 30 are ages. That's also true in function calls that do not use keyword arguments (the vastly prevalent paradigm in mainstream languages), but function calls specify a function name which can reveal something, like set_age(john, 45). Some languages have both. No knowing anything about Nim, I have no reason to believe that it has no way to achieve a compact way for initializing an array or list of objects using just positional arguments, and no repetition of the type name. If nothing else, surely there has to be a way to write an array of tuples, and that aggregate can surely be passed to some function that iterates over it and constructs the implied Person objects. On the C++ front, I seem to recall C++ recently adding C99 designated initializers or planning to. If so, then { .name = "John", .age = 45 } will be possible, and C++ coders will end up using it.
- pjmlp 7y agoC++ designated initializers are not like C99 designated initializers, rather a subset. For example, just like initialization lists on constructors, initialization order is relevant.
- kazinator 7y agoOrder is unspecified in C initializers, including designated ones. That quickly becomes relevant when the program depends on it for expected behavior.
- nimmer 7y agoYou can use tuples in Nim and it would be almost identical.