5 ms·
And that's exactly what's different in D, where the audience for meta-programming is "everyone". It's not just about more power, but how accessible this power i
by p0nce 8y ago
And that's exactly what's different in D, where the audience for meta-programming is "everyone". It's not just about more power, but how accessible this power is. To think you need to suffer to have this power is not true.
- inetknght 8y agoNothing stops "everyone" from using the features which suit library developers.
- adrianN 8y agoExcept ever increasing time to learn all the language features and associated best practices.
- inetknght 8y agoWhile true on the face of it: I haven't had the need to learn many other languages so I haven't had the need to learn the best practices of them. Use what you need, learn what you need. Don't pay for what you don't use :)
- gumby 8y agoIndeed, but as a large, general-purpose system programming language there are many features that support certain important and special cases, with no application of the language, even library development, using them all. As an example, we needed locked containers, so wrote a little template and specialized it over the couple of containers we needed. It supported just what we needed. If this same functionality were extended to the standard container library it would not only have need to be thought out to handle every non-locking case, but would have either needed a lot of repetitive boilerplate (and repetitive specializations) or else additional hair that was not worth our while to learn/use. We were able to avoid the problem by adding some documentation in the local style guide.
- p0nce 8y agoYou can't in C++ because learning the language takes 10 years and is a never-ending story.
- kllrnohj 8y agoD vs. C++ in this list of examples looked equivalently complex and equivalently power-user focused. static if not introducing a new scope seems like the sort of confusing, error-prone edge case that trips up newcomers, for example. We are taught very early on that in C-style languages curly braces means a scope. Except here in D in this particular case for some reason it's not that isn't clear why until you are very deep into understanding the language. Similarly operator overloading via a string that tells you what you are overloading seems... insane? Very error-prone & complex? Not that C++ is great here or anything, but it seems disingenuous to claim D's complex thing is for everyone while C++'s nearly equally complex thing is too complex for everyone.
- p0nce 8y ago> Similarly operator overloading via a string that tells you what you are overloading seems... insane? Very error-prone & complex? Frankly you should try D for just 5 minutes and see for yourself, because no it is really sane and works well. Never seen anyone complain about this... See here it is used to implement all operators for small vectors in 46 lines: https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/math/vector.d#L171 https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/m...
- kllrnohj 8y agoIt appears to only be primarily useful if you are writing a pure wrapper class where you proceed to delegate to an actual implementation. But you could still do that and not be string-based. It could (and should!) be an enum of the operator instead. opBinary takes a fixed number of ops, but the parameter type of string has an infinite number of values. Whether or not the design of having a single operator overload method is a good idea or not is independent from what I'm specifically calling insane which is that the parameter type to that method is a string.
- p0nce 8y agoIf it is string-based meta-programming you find ugly (as many do as first), consider the alternatives are maybe not much better in practice. https://forum.dlang.org/post/l5srs7$2m3$1@digitalmars.com https://forum.dlang.org/post/l5srs7$2m3$1@digitalmars.com
- pjmlp 8y agoOn the other hand, templates get abused on D as workaround to avoid writing attribute boilerplate across all functions definitions.