# Re: Non-declared variables

**URL:** <https://www.ruby-forum.com/t/re-non-declared-variables/72340>\
**Category:** Ruby\
**Created:** [October 16, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340 "2006-10-16T17:10:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/1 "2006-10-16T17:10:17Z")

</div>

From: Avatar [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> Are there real tangible benefits that non-declared, dynamically typed  
> (at binding time) variables provide? Or do dynamic variables simply  
> create less compile time errors and more (harder to catch) runtime  
> errors?

Every language feature that reduces how much typing I have to do is a  
tangible benefit to me. It eases stress on my body machine, and speeds  
the delivery of my code.

The only downside I can think of is that typos may not be caught for  
instance/class variables as readily:

class Foo  
def bar  
@somethingDelicious = 12  
end  
def whee  
print( @sonethingDeIicious )  
end  
end

If you personally find that you are having trouble in this arena, I  
suspect that it wouldn’t be hard to write a code analyzer that alerted  
on potential misspellings. I’ve personally not needed it.

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/2 "2006-10-16T17:30:22Z")

</div>

On Tue, 17 Oct 2006, Gavin K. wrote:

> The only downside I can think of is that typos may not be caught for
> 
> If you personally find that you are having trouble in this arena, I  
> suspect that it wouldn’t be hard to write a code analyzer that alerted  
> on potential misspellings. I’ve personally not needed it.

for those of you using vim, the completion feature virtually eliminates  
this  
kind of bug. for instance, i can type @som, then hit ‘ctrl-n’, and  
@somethingDelicious simply appears. this is a huge bug stopper for me,  
because i reely cant spel.

fyi.

-a

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/3 "2006-10-16T17:36:29Z")

</div>

> Every language feature that reduces how much typing I have to do is a  
> tangible benefit to me. It eases stress on my body machine, and speeds  
> the delivery of my code.

That seems a ridiculous thing to say to me. Time taken to type out  
code is not the limiting factor in your productivity.

If you sacrifice readability, maintainibility, safety, extensibility  
or supportibility for a fewer characters, it’s hardly a worthwhile  
tradeoff.

Terseness is not a virtue. If it were, I’d be a perl programmer.

Martin

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 5:48pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/4 "2006-10-16T17:48:31Z")

</div>

On Oct 16, 2006, at 10:29 AM, removed\_email\_address@domain.invalid wrote:

> > tangible benefit to me. It eases stress on my body machine, and  
> > def whee  
> > eliminates this  
> > kind of bug. for instance, i can type @som, then hit ‘ctrl-n’, and  
> > @somethingDelicious simply appears. this is a huge bug stopper for  
> > me,  
> > because i reely cant spel.

In TextMate this is done with the escape key and I couldn’t agree  
more about it being an excellent habit to get into.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/5 "2006-10-16T18:16:43Z")

</div>

Gavin K. wrote:

> If you personally find that you are having trouble in this arena, I  
> suspect that it wouldn’t be hard to write a code analyzer that alerted  
> on potential misspellings.

Here’s a simple example I just came up with. (If this were to be taken  
a little further, it should probably report line numbers. If it were to  
be taken a lot further, it should probably use actual parsing of Ruby  
code to determine class scope for variables, leave out things that look  
like variables inside strings/regexp/comments, etc.)

require ‘typochecker’

class Foo  
def foo  
@@name = ‘boot’  
@name = ‘wow’  
@somethingDelicious = 12  
end  
def whee  
print( @mane, @@names )  
print( @somethingDelicions )  
end  
end  
#=\> Possible typo: @@name versus @@names  
#=\> Possible typo: @name versus @mane  
#=\> Possible typo: @somethingDelicious versus @somethingDelicions

(typochecker.rb)

# [http://po-ru.com/files/levenshtein/1.3/levenshtein.rb](http://po-ru.com/files/levenshtein/1.3/levenshtein.rb)

require ‘levenshtein’

source = IO.read( $0 )  
cvars, ivars = source.scan( /@{1,2}\w+/ ).partition{ |v| /^@@/ =~ v }  
[cvars, ivars].each{ |vars|  
vars.each\_with\_index{ |v1, i|  
vars[(i+1)…-1].each{ |v2|  
if Levenshtein.distance( v1, v2 ) \<= 2  
warn “Possible typo: #{v1} versus #{v2}”  
end  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/6 "2006-10-16T18:49:06Z")

</div>

> it’s not the actual typing of the lines that takes so long - it’s reasoning  
> over it.

Yes, which is really my point. It’s not about reducing keystrokes.  
it’s about expressiveness.

Martin

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 16, 2006, 6:43pm UTC](https://www.ruby-forum.com/t/re-non-declared-variables/72340/7 "2006-10-16T18:43:05Z")

</div>

On Tue, 17 Oct 2006, Martin C. wrote:

> Terseness is not a virtue. If it were, I’d be a perl programmer.
> 
> Martin

i translated a c option parer. this one:

jib:~/shared/dmspnl\_new/grid\_ols \> wc -l commandline.h commandline.c  
67 commandline.h  
699 commandline.c  
766 total

it even uses getoptlong to reduce the busywork. in ruby it’s about 40  
lines.

it’s been proven (many times - google it) that programmers write the  
about the  
same number of lines of code per day regardless of the language, be it  
assembler or ruby. so, given that it might take be something like 30  
minutes  
to produce a 40 line option parser in ruby, we can interpolate that the  
equivalent c parser would take about two and half days to produce.  
that’s  
quite expensive if you ask me, espcially considering that there is no  
good  
reason (speed for example) to parse options in c.

it’s not the actual typing of the lines that takes so long - it’s  
reasoning  
over it. without even seeing the code i’m sure you’ll have no trouble  
believing that the ruby opt parser takes seconds to comprehend, while  
the c  
one takes considerably longer - simply based on it’s size.

and this point isn’t even considering security faults, which have been  
shown  
to scale linearly with tloc.

-a
