From: Rudolf Polzer Date: 2002-09-27T18:41:38+09:00 Subject: Re: Ruby - common pitfalls? Scripsit ille aut illa Gavin Sinclair : > From: "Rudolf Polzer" > > The problem is just that this if line is equal to Pascal's: > > > > if foo = nil then > > begin > > { ... } > > end > > > > Note that the first line is completely equal. When reading the above > > code, I'm tempted to "parse" it as Pascal code and oversee the > > assignment. > > > > > Also, you know, the parentheses are really > > > optional in the condition, independent of all other things. > > > > The problem is just, that it: > > > > - looks better with the "then" > > - if the "then" is there, it looks like Pascal > > > > But I just found a workaround (which already works): > > > > if foo == nil; then # bash-like > > # ... > > end > > > > Maybe it's less tempting to write a Pascal-style equality test if the if > > syntax does not look exactly like Pascal. > > Instead of finding "workarounds" to make Ruby look like Pascal or Bash, why not > just learn Ruby properly? Use -w always. -w tells you the error *after* you have done it. It would be better it it would not happen at all. And sometimes such code is written on purpose: if retval = foo # use retval end creates a warning. if retval = foo () # ... end creates another one ("foo (...) interpreted as method call"). What else could it be? To me it just looks better when there's a space between the method name and the opening brace. I know it is interpreted as method call then and not as first argument. Is there a way to disable this single warning? > > ---------------------------------------------------------------------------- > > > > - a %= b versus %=...=. A syntax highlighter gets into big trouble when > > > > seeing this construct. Nothing really seriuos, but I already had to > > > > insert "useless" comments to fix vim's highlighting - which is unable > > > > to correctly highlight if-then-end expressions. Perhaps it would help > > > > to deprecate %=...= as string separator (any other character could be > > > > used with less problems). > > > > > So use another character. *I* use another character. But when I use %= to get the modulus (a %= 3), vim's highlighting fails and I have to write a comment (#=) to make vim highlight the rest of the code correctly. I don't want to always write a = a % 3 just to make it easier to vim. -- [mpg123d] Just playing: .../albums/vintage/a/09 hesitation.mp3 Quatsch wird immer qu�tscher, bis er quietscht.