3 ms·
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`, when call
by mathieuh 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`, 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).
- Aaargh20318 9y agoAppleScript may be the only read-only programming language in existence.
- sethrin 9y agoDepending on your definition of programming language, that crown might actually go to HAGGIS. It's an "educational" programming language which is not executable (or intended to be). It's possibly the worst idea in the history of computing, and that it is taught to anyone is (IMO) a public offense. https://en.wikipedia.org/wiki/HAGGIS https://en.wikipedia.org/wiki/HAGGIS
- justbaker 9y ago"ah, scary, close tab!"
- dTal 9y agoI get that vibe from Inform 7: the famous Dijkstra’s algorithm reads like English, but I'd have no idea how to write such a program.
- throwaway7645 9y agoInform7 is mostly for text adventures. I'm sure it's not bad if you give it a go as many people with little to no coding experience write expansive text games using it.
- mpweiher 9y agoI am still waiting for the combination of Perl and Applescript. You have to write it in Applescript, but you get to read it only in transliterated Perl.