5 ms·
Alternate (better) solution to the author's problem: Use a language where all parameters are named, like Smalltalk or Objective-C. document addObserver:obs
by mpweiher 12y ago
Alternate (better) solution to the author's problem: Use a language where all parameters are named, like Smalltalk or Objective-C.
document addObserver:observer forNotificationNamed:'load' isWeak:false.
xhr openURL:options url type:options type async:options sync negated
- Argorak 12y agoBut even there, I would prefer: [document addWeakObserver: observer forNotificationNamed: 'load'] and [document addObserver: observer forNotificationNamed: 'load'] Assuming for a second, that the non-weak observer should be the normal case.
- BurningFrog 12y agoSo wordy and repetitive and wordy.
- jjoonathan 12y agoNot a problem if autocomplete is working.
- exDM69 12y agoThe issue with autocomplete is that it makes writing a lot of code really easy but offers no help when reading the code. Syntax/semantic highlighting may help a little but the issue is still there. Given that more time is spent reading than writing code, autocomplete is only a partial solution to this problem.
- yoz-y 12y agoI consider verbose code to be more readable in general. However one has to take more time when naming their functions and parameters.
- mpweiher 12y agoThis comment makes sense for the original problem, but not for the message you're replying to, as keyword parameters help tremendously with readability.
- BurningFrog 12y agoI've never worked in those languages, but I suspect I'd end up with a lot code like this: foo(author: author, title: title, price: price) The problem in the article is real, but it is the exception. If it's hard to see what 5% of your parameters mean, forcing 100% of them is probably a cure worse than the disease. When I worked in Java with IntelliJ, the solution was to simply hover over the call, and the declaration would appear.
- jjoonathan 12y agoIDEs fix both problems: writing verbose code and reading terse code. The thing is, code isn't always examined in a working IDE, and it tends to be read outside of an IDE more than it tends to be written outside of an IDE. The disease is far worse than the cure. I frequently (at least once a day) find myself wishing code was written in the smalltalk style but I've only found the smalltalk style inconvenient on a small number of occasions.
- mpweiher 12y agoWhile I can't speak to what you would end up with, my experience (~quarter of a century) is that this is not the case. To verify, I just did ack '\[.*:' | less to search my code-base for message sends with parameters. Scanning the first hundred or so results shows the pattern you mention to be rare. Dan Ingalls explains the syntax really nicely in this video: https://youtu.be/P2mh92d-T3Y?t=600 With this type of syntax, most APIs turn into EDSLs all by themselves, and often read like fairly natural sentences. I ramble on a bit about the relationship between keyword syntax and (lack of) operator overloading: http://blog.metaobject.com/2015/03/why-overload-operators.html
- fyolnish 12y agoSo memorable.
- bbcbasic 12y agoMuch bugfree
- 1wd 12y agoAlternate (even better) solution: Use a language where you can optionally name parameters, like C#. xhr.OpenUrl(url, async: true);
- gmac 12y agoActually, even in Objective-C it's technically optional to give your parameters names. Feel free to knock yourself out with method signatures like: - (void)doMysteriousThingsWithParameters:(int)x :(BOOL)y :(NSString*)z; I've come across this recently when creating an HTML5 <canvas> context object to be called from within JavaScriptCore. This needs to expose JS-friendly methods like: - (void)strokeRect:(CGFloat)x :(CGFloat)y :(CGFloat)w :(CGFloat)h; - (void)arc:(CGFloat)x :(CGFloat)y :(CGFloat)radius :(CGFloat)startAngle :(CGFloat)endAngle :(BOOL)antiClock;
- 1wd 12y agoInteresting. I don't use Object-C, but always heard parameter names are actually considered to be part of the method name there. Was that wrong? Ah, or do you mean the name is just empty? How does that work on the implementation side? I.e. how do you refer to the passed arguments?
- fyolnish 12y agoParameters don't have names, the message has a format, and th only rule of that format(referred to as a "selector") is that parameters are preceded by a :
- anton_gogolev 12y agoMore, more parentheses!
- _ZeD_ 12y agotoo much verbose. I prefer python approach, where you can set "optionally named" and "kwarg only" parameters" on a per function basis. For a description, see https://www.python.org/dev/peps/pep-3102/ https://www.python.org/dev/peps/pep-3102/
- jjoonathan 12y agoOh come on, we both know that if you give people a choice the feature will be underused. If you want proof just look at python code!
- _ZeD_ 12y agoI don't understand. What you mean?