5 ms·
smalltalk cutest feature is the named parameter syntax trick (I don't like tricks but let's make an exception). make-range from: 10 to: 20 calss (make-range.fr
by agumonkey 9y ago
smalltalk cutest feature is the named parameter syntax trick (I don't like tricks but let's make an exception).
make-range from: 10 to: 20 calss (make-range.from:to 10 20) or something similar. Free nanodsls
smalltalk simplicity lies in that the metamodel is actually human reasoning friendly, even while dynamic, you have a clear picture of what's gonna happen in case of errors etc. It didn't please visual age users, which called smalltalk messagenotunderstoodlang but I believe it was due to the wrong viewpoint.
- hota_mazi 9y ago> smalltalk cutest feature is the named parameter syntax trick (I don't like tricks but let's make an exception). And yet, Smalltalk got it wrong by making all the parameter names mandatory, which leads to sources that are much more verbose than they need to be. The correct approach to this is to make parameter names optional, so they're only used when disambiguation is necessary to clarify the intent of the code.
- igouy 9y ago> by making all the parameter names mandatory For example?
- rahoulb 9y agoIn smalltalk the parameter names aren't mandatory in the sense of many other languages. They are actually part of the method name. So robot put: thing in: container. And robot put: thing on: shelf. Are two separate messages that are both understood by the robot instance - "put: in:" vs "put: on:"
- igouy 9y agoI asked hota_mazi to provide an example which demonstrated what they were talking about, to explain why they said "Smalltalk got it wrong by making all the parameter names mandatory". Are you hota_mazi ?
- hota_mazi 9y agoIn languages where parameter names are optional, you can say foo(1, 1, create = true) This is the best of both worlds, allowing you to only name parameters when there can be ambiguity (for example when the function takes two int parameters and both mean very different things). Smalltalk forces you to always name your parameters, which leads to overly verbose source files.
- igouy 9y agoI don't think any of us know what: foo(1, 1, create = true) :is supposed to do. Please show a meaningful example so we can see whether the Smalltalk is overly verbose or your alternative is overly ambiguous.
- hota_mazi 9y agoI tried to pick up an example as generic as possible so you could understand my general point instead of focusing on this specific example, and you choose to focus on this specific example. <sigh>. How about this: createWindowAtCoordinates(10, 10, redraw = true) vs createWindowAtCoordinates(x = 10, y = 10, redraw = true) Regardless of how you feel about this specific example, surely you can agree that it's not always necessary to specify all the parameter by names?
- igouy 9y agoSo you mean that in this case we might assume the conventional order x coordinate first and y coordinate second would be understood. However (the specifics always matter) if we're assuming that, and we're bothered about verbosity then why say: createWindowAtCoordinates(10, 10, redraw = true) :instead of assuming that it will be understand that the window will be created at a point: createWindowAt(10, 10, redraw = true) :and something more like a Smalltalk method send: Window new openAt: 10@10 redraw: true :where we've used the x then y convention, and a binary message @, to create a point (without mandatory parameter names).
- 9y ago
- Chaebixi 9y ago> metamodel is actually human reasoning friendly There's so much power in being able to think about a language (or your application) without having to always dig into the code.
- pmoriarty 9y ago"smalltalk cutest feature is the named parameter syntax trick..." make-range from: 10 to: 20 calss (make-range.from:to 10 20) or something similar. Free nanodsls For the uninitiated among us, what does that do and what's so magic about it?
- mathieuh 9y agoYou can put the parameter names in method calls, which makes for much more readable code. Like a makeRange method may take parameters `from` and `to`, when calling this method you could do `makeRange(from: 0, to:10)`. That’s a fairly trivial example but it demonstrates how readability is improved. You can imagine how this becomes even more useful with methods that take many parameters. An interesting document to look at regarding this is Swift’s guidelines on naming methods.
- pmoriarty 9y ago"You can put the parameter names in method calls, which makes for much more readable code. Like a makeRange method may take parameters `from` and `to` ... That’s a fairly trivial example but it demonstrates how readability is improved." Is that something like keyword arguments in Lisp?
- mbrock 9y agoExcept Smalltalk keywords can't be reordered or omitted. It's more like you put the arguments in the middle of the method name, like a kind of mixfix notation. The method name would be "rangeFrom:to:withStep:" and that means you call it exactly like that, with arguments after the colon. Objective C is the same.
- mpweiher 9y ago> makeRange(from: 0, to:10) [..] Swift’s guidelines on naming methods. The syntax you show is Swift, which is a weird mash-up of C/C++ style function call/method call syntax with keywords jammed into them. To me, actual Smalltalk syntax is just so much cleaner: 0 to: 10. It manages the "reads like english" trick without trying to be english-like or natural-language-like. (See Applescript for the disaster that results from that: "Many of the current problems in AppleScript can be traced to the use of syntax based on natural language" http://www.cs.utexas.edu/~wcook/Drafts/2006/ashopl.pdf http://www.cs.utexas.edu/~wcook/Drafts/2006/ashopl.pdf).