From: Dossy Date: 2002-07-18T02:07:24+09:00 Subject: Re: Syntax "surprise" On 2002.07.18, Brad Cox wrote: > > Its not a language's business to prevent users from writing "smelly" code. Um, right. When you believe this, you end up with Perl. I love Perl dearly, but there's a reason why I've stopped doing any new development in Perl and everything in Ruby now. I don't think a language should constrain you from being able to do things, but I don't feel constrained by Ruby _at all_. If the constraints keep people from writing smelly code -- which I may, some day, have to interface with, read, understand, change or modify -- but the constraints don't feel constraining _to me_ ... I can only see that as a Very Good Thing. > Long argument lists are common in data initialization contexts, Bad code is common. You're very right. I recently took an #initialize in a class that took 5 args (4 Arrays and one Hash) and refactored it a few times so that the constructor only took one Array of Hashes (to be specific, all of the DBI::Row objects for the result set of a SQL query via DBI). Then, I added methods to the class to set the various other attributes -- anything "unset" got a sane default value, so I only had to "override" things that needed to be changed, as to explicitly setting them in the other 4 Array args as I was doing before. The design is much cleaner, certainly easier to read and understand and is far less smelly. It's still smelly (there's a strong feeling of duplication that I'm trying to eliminate) and I think it's time to introduce polymorphism or someother such refactoring soon, but I'll do that when I write the next test case that feels difficult to implement because of the way things currently are. > and misplaced commas a extremely common problem, that's actively > manufactured by this rule. Yes, and misplaced commas are more often a mistake than an intention. So, I prefer the language to at least warn me that I've done it -- making it a fatal error isn't a big deal, anyway. How hard is it to find a misplaced comma when the program won't even run because of it? Trivially easy to find. How hard is it to track down a bug _because_ of a misplaced comma which the language finds perfectly acceptable and within the rules? Pretty damn near impossible sometimes, especially if you're tired. If you're really desperate for having "optional trailing commas" the Array expansion trick described earlier in the thread gives it to you with no change to the language itself. Wrapping the arg. list in *[] is a way to express the intentional desire to support an optional trailing comma which is good. Having that behavior by default is too magical and will only cause more harm than good when people make honest mistakes. -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)