4 ms·
(For those who were wondering, the article is about DSLs in Kotlin). DSLs can be very elegant ways to improve code readability (as long as the assumptions and
by athenot 9y ago
(For those who were wondering, the article is about DSLs in Kotlin).
DSLs can be very elegant ways to improve code readability (as long as the assumptions and language they use is meaningful to the team).
This is an area that I wish node.js had invested in. Perl6 has "slangs" which are extremely powerful, see [1] for some examples that just flow elegantly. Combine that with custom operators to write code like "4.7kΩ ± 5%" that would make sense to electronicians [2] and you can get some really user-friendly syntaxes.
(Again, it bears repeating that a DSL improves readability by sacrificing generality, so a DSL is for audience that's usually a subset of that language's users. That electronics code would be useless to the average web developer.)
[1] https://github.com/tony-o/perl6-slang-sql https://github.com/tony-o/perl6-slang-sql
[2] https://perl6advent.wordpress.com/tag/dsl/ https://perl6advent.wordpress.com/tag/dsl/
- kqr 9y ago> a DSL improves readability by sacrificing generality, so a DSL is for audience that's usually a subset of that language's users. You'd think that'd be self-evident from the "domain specific" in the name, but I guess a lot of things are obvious once they're pointed out to you...
- wahern 9y agoWow. The Perl6 slang feature is awesome. I can't believe I missed it. I haven't had a chance to use Perl 6 but I would really like an excuse. I love Lua's LPeg module. Perl 6 has deeply embedded PEGs (i.e. Grammars, aka parsing combinators) into it's design. Knowing first-hand how powerful PEGs can be if the engine and language integration is implemented well, I've never doubted the awesomeness and elegance of Perl 6. It's unclear to me if Perl 6 Grammars' Action feature is as powerful as LPeg's capturing and inline transformation primitives[1], but the fact that you can plug a grammar into Perl 6's parser is crazy awesome. I'm not surprised Slang exists--I've known it was possible; just surprised that it's a module and idiomatic pattern and I hadn't read about it before. [1] See http://www.inf.puc-rio.br/~roberto/lpeg/#captures http://www.inf.puc-rio.br/~roberto/lpeg/#captures Most PEG engines just return your raw parse tree as a complete data structure and require you to fix it up manually. LPeg has really well thought-out extensions that allow you to express capture and tree transformations much more naturally; specifically, inline (both syntactically and runtime execution) with the pattern definition(s).
- sametmax 9y ago> 4.7kΩ ± 5% And now ask somebody to type those unicode chars on the top of his/her head... Plus how do you look what it does in google ? In a a documentation ? How do you generate documentation for those ? Cause you have no method name, no class name, nothing. And then what's the exact implementation behind it ? Does it do something funny ? So I have to mix the dozen of funny details of all the code from the guys who though the 20 times they do this super-important-operation they need to recreate a whole new syntax ?
- TeMPOraL 9y ago> And now ask somebody to type those unicode chars on the top of his/her head... That's about the only problematic thing with this, though your editor should let you do it relatively easily; if it doesn't, find a one that doesn't suck ;). > Plus how do you look what it does in google ? In a a documentation ? How do you generate documentation for those ? Like with any other piece of API code. There's nothing special here. > And then what's the exact implementation behind it ? Does it do something funny ? So I have to mix the dozen of funny details of all the code from the guys who though the 20 times they do this super-important-operation they need to recreate a whole new syntax ? Check the associated documentation, or source code if available. I get the impression programmers nowadays are afraid of reading the source of stuff they use.
- athenot 9y ago> > And now ask somebody to type those unicode chars on the top of his/her head... > That's about the only problematic thing with this, though your editor should let you do it relatively easily; if it doesn't, find a one that doesn't suck ;). On macOS, and on a qwerty keyboard: • Ω is Option Z • ± is Option Shift = (or Option + if you look at it another way) Many moons ago, HyperTalk (and I think AppleScript still does) supported ≥, ≤ and ≠ as shorthands for >=, <= and !=; and they were typed as Option >, Option <, and Option = respectively (fewer keystrokes).
- sametmax 9y agoYou really need to work outside of your 10x bubble. This is scary to see you completly ignore common dev issues.
- LunaSea 9y agoHaving read a lot of Python code that uses scientific libraries that override operators and key indexing I'll have to disagree. The result is easier to read if you're familiar with it but exponentially more complicated if you're not and still learning. It creates marginally shorter code but I feel like the sacrifice of the explicitness / verbosity of a normal method / function call isn't worth it.
- goatlover 9y agoThose libraries also make it easier to write that code. The majority of people using scientific libraries will be used to mathematical and scientific notation, so the closer the programming is to that, the better for them.
- posterboy 9y ago> key indexing sure, that should come with a huge warning sign in the documentation. Edit: and as code should be self documenting, that warning sign could be an extra function, sure.