How much would variable declarations in Ruby make you wince?

  • Thread starter Just Another Victim of the Ambient Morality
  • Start date
M

Marc Heiler

Hi, to respond briefly towards
"There are actually at least two measures that help preventing this: 1.
use an editor with proper syntax indentation and highlighting." [...]
"2. Exercise the habit to enter matching pairs always together before you
enter the content

What makes you believe I do not already? ;)

But editor aside, there is a huge difference in visually appealing
on something. The greatest IDE can make Java [*1] look great, folding
away
all the ugly bits, but under the hood it still remains ugly and
needlessly
verbose. Your brain adapts to the ugliness and blends away the
yucky parts, but the ugliness is still there, and the great
editor just conceals it, like a veil.

In this regard, I do find no "end" visually _more_ appealing to
my eyes than an existing "end". Or multiple ones, if one chose
to rely on heavy if-else branching.

It is not without reason that people prefer python or ruby these
days compared to perl. Years ago perl had no real competition,
it was still used heavily (and still is), but was it visually
really appealing? I think I wrote only about 100 .pl scripts,
compared to around 2000 .rb files so far.
I never had the impression that perl bothered at all about
visual elegance.

It is not a question of habit. Habit changes over time, you
adapt anyway. You have to use "workarounds" everywhere
too and can use your editor to easen up the workload.

It is a question of beauty and elegance.
This is a more general remark, don't think I am focusing
only on 'end' - 'end' is not that important anyway ;)

[*1] Replace Java with another language as you see fit.
I could mention (((lisp))) but I am afraid i would get
(burned) ...
 
D

Dumaiu

On Dec 8, 6:51 pm, "Just Another Victim of the Ambient Morality"
1.) How does predeclaration help?
var l = [1,2,3]
var h = {:a=>"b"}
wants_an_array(h) # => error

It wouldn't help at all and no one claimed that it would. Did you read
my post?
2.) While that may alleviate the typo problem, it introduces another
class of bugs which are just as subtle:
var list = create_useful_list
if should_modify_list(list)
# I meant to modify the variable "list" here...
var list = modify_list(list)
end
use_list(list)
Once one became accustomed to typing "var", there is every chance that
it would be used places where a pre-existing variable was meant, but
the "var" just got typed out of habit.

You don't really believe this, do you? Do you program in C/C++ at all?
Do you find yourself accidentally typing "int" when using a variable or
function in that language?
Just because you need this keyword for declaring variables doesn't mean
you're going to get so used to typing it that you'll accidentally type it
out all the time. That's just silly...

I don't really think it's equitable to liken Perl, where all you
do is use 'my', 'my', 'my', to C++, where the typing forces you to
really think about what you're instantiating. There is more room for
error in Perl.
 
D

Dumaiu

[*1] Replace Java with another language as you see fit.
I could mention (((lisp))) but I am afraid i would get
(burned) ...

...or receive the "death of a thousand 'cdr's." Can't resist.

-J
 
D

Dumaiu

From: "Dumaiu" <[email protected]>




For what it's worth, I'd suggest that the phrase "premature
optimization" may be more akin to canon, than buzzword, and
tends to mean something very specific.

(By canon, I mean, "the body of rules, principles, or standards
accepted as axiomatic and universally binding in a field of study
or art.")

For completeness sake, the original appearance of the phrase in
publication:

"We should forget about small efficiencies, say about 97% of
the time: premature optimization is the root of all evil."

(Knuth, Donald. Structured Programming with go to Statements,
ACM Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268.)
((Knuth is said to have been parahprasing C.A.R. Hoare))


I think I *was* actually offended. <grin> But it was obviously
based on a misunderstanding.

I don't think I've achieved ideal balance yet... I'm usually
coming at it from the other direction: skipping a few refactorings
until I realize some part of the code is really bothering me, then
having to make time for a larger cleanup. But hopefully I'm
improving.

Regards,

Bill

I've had a chance to think some more. First, is the word 'canon'
canonical? I mean, do I have to use it? I've not encountered a field
outisde of computer science or the Roman Catholic Church in which
standards would be described as canon, even if they were 'universally
binding,' which they aren't. It makes me feel like we ought to be
arguing about Star Wars or something.
But on a more serious note: I am bemused by the discovery that I
still cannot convince myself of any fundamental distinction of intent
between what we call the processes of optimization and of refactoring,
despite the great differences in procedure by which they are
undertaken. I earlier made the error of trying to see the issue in
terms of performance v. "good design," you could say, but it's really
more like a radial tug-of-war between many competing priorities.
After all, even when optimizing purely to decrease the load on the
computer, you still have to choose which *part* of the computer needs
the most attention. By comparison, you refactor code to decrease the
load on at least one, but never all, of the human "parts" of the
software project. And it's blurred further within the domain of
dynamic languages. Even if you think only of maintainability, i.e.,
the human element, tradeoffs must still be made: the more you separate
interface from implementation, the uglier the implementation is going
to get.
Is that a contentious statement? I'm spinning this out as I go. Let
me know know what you think.

-Jonathan
 
J

Just Another Victim of the Ambient Morality

Eivind Eklund said:
I think maybe we would communicate better if you read what you were
replying to?

One strength of Ruby - an important one - is that it is succinct.
There is very little extra noise compared to what is strictly
necessary to say what the program is doing. Your proposal introduce
extra noise. This noise has a cost for readability in some cases. My
opinion is that this cost is higher than the utility of the construct,
as the construct guard against an error that is easy to guard against
in other ways, other ways that are generally better, like unit
testing or string completion.

I disagree that "succinctness" is an important part of Ruby's strength.
At least, not in the same manner that I think you mean it. Ruby lacks much
of C/C++ redundant "scaffolding code" (a term I've made up) and that lends
it power. However, I don't think variable declarations are redundant.
There are times when you deliberately mean to create a variable and there
are times when you don't. This is a real distinction and it takes real
information to distinguish it, although not much in my opinion.
Besides, if you were really serious about reducing "line noise," you'd
be advocating Python-esque whitespace block definitions. Seriously, what's
with all these "end" keywords sprinkled all over the place? That's just
extra noise. Surely you want to remove that noise, right? Right?

This depends on code style. Those that use a lot of short methods
also have more variable declarations compared to variable assignments,
in my experience.

...those that use a lot of short methods and make use of short lived
variables rather than a more functional structure, yes, have more variable
declarations. Still, I don't think it's so bad...
 
G

Gerardo Santana Gómez Garrido

On 12/8/07, Just Another Victim of the Ambient Morality
What do you all think?

I think 47 messages (48th with mine) is A LOT. I don't think the
subject deserves such attention. There's already TOO MUCH NOISE in
this mailing list.

And I think I've got a solution for your problem. It's a crazy idea:

what about if instead of bending a language to your preferences you
actually, you know, learn to type.



P.S. I wonder if these people are real. Sometimes I think they're just
[Perl|Python|Java] trolls testing our patience or wasting our time on
purpose.

If you are honest, JAVotAM, get a grip: that change you're thinking
of, won't happen.
 
T

Trans

[snip]
What do you all think?

I think 47 messages (48th with mine) is A LOT. I don't think the
subject deserves such attention. There's already TOO MUCH NOISE in
this mailing list.

And I think I've got a solution for your problem. It's a crazy idea:

what about if instead of bending a language to your preferences you
actually, you know, learn to type.

P.S. I wonder if these people are real. Sometimes I think they're just
[Perl|Python|Java] trolls testing our patience or wasting our time on
purpose.

What gets me, is that so many people respond to threads like this.
While other, much more reasonable ideas get so little attention.

T.
 
D

Dumaiu

I think 47 messages (48th with mine) is A LOT. I don't think the
subject deserves such attention. There's already TOO MUCH NOISE in
this mailing list.
And I think I've got a solution for your problem. It's a crazy idea:
what about if instead of bending a language to your preferences you
actually, you know, learn to type.
P.S. I wonder if these people are real. Sometimes I think they're just
[Perl|Python|Java] trolls testing our patience or wasting our time on
purpose.

What gets me, is that so many people respond to threads like this.
While other, much more reasonable ideas get so little attention.

T.


Although I don't think it is the case, if what Mr. Santana Gómez
Garrido said in his above post--which I presume he intended as a sort
of coup de grâce for the thread--is true, and the original poster is a
troll, then the real problem is that there are a bunch of us
respondents hanging around who are too stupid to know better. So you
really wouldn't want us participating in the 'more reasonable'
discussions, would you? The problem takes care of itself.
If you still aren't convinced that we are a lost cause, by all means
recommend such a topic.

-J
 
J

Just Another Victim of the Ambient Morality

Gerardo Santana Gómez Garrido said:
On 12/8/07, Just Another Victim of the Ambient Morality


I think 47 messages (48th with mine) is A LOT. I don't think the
subject deserves such attention. There's already TOO MUCH NOISE in
this mailing list.

First of all, if you don't think the subject deserves any attention, why
pay it any?
Secondly, why do you think there's too much "noise" in the mailing list?
Are you not capable of threading the discussions with your mail client? Do
you think there's too much noise _despite_ threading the discussions? I can
understand if you think there's noise but... too much noise?

And I think I've got a solution for your problem. It's a crazy idea:

what about if instead of bending a language to your preferences you
actually, you know, learn to type.

That's about as helpful as responding to someone who's having trouble
with something by saying "grow a brain." It sounds like you're the one
making noise, here...

P.S. I wonder if these people are real. Sometimes I think they're just
[Perl|Python|Java] trolls testing our patience or wasting our time on
purpose.


If you check Google Groups, you'll see that I've been here a some time,
now. I'm quite real and sincere...

If you are honest, JAVotAM, get a grip: that change you're thinking
of, won't happen.

If you read the subject line for this thread, you might get an inkling
of how confident I am that this change will ever happen.
I thought it's been an interesting thread. I don't see why it has
bothered you so much. If you don't like the subject matter, don't read it.
How hard is that? It seems that you're the one who's lost a grip...
 
J

John W. Kennedy

Just said:
I actually don't think this is the case. Statically typed languages
didn't come from long experience with bugs, it was just happenstance...
If I'm not mistaken, typed variables came from a world where compiled
programming languages failed to completely shield the user from the
hardware. Back then, you had to declare variables so that the compiler can
know to allocate them from static store when creating the executable image.
Later on, when functions became more popular, they also had to do this for
the stack. A lot of C syntax comes from how close it is to assembly
language...

This depends on exactly what you mean by "static typing". If you mean
the restriction that a variable must be, for its entire life, one
particular type (in Java terms, byte, short, int, long, float, double,
or char), it has far more to do with the fact that, on 99.9% of
hardware, "a = a + 1" requires different object code in each of these
cases. A language that, like Ruby, Perl, REXX, LISP, BASIC (as
originally conceived), or APL, does not impose this rule cannot, in
general, be compiled into respectable object code at all. Ruby's
pure-object orientation makes things a little better, but still involves
massive use of dispatching code that Fortran, COBOL, PL/I, C/C++, Ada,
or Java does not need.

But "static typing" has also meant other things.
 
R

Roger Pack

The two most popular sources of bugs for me when programming in Ruby
are:

1) Passing the wrong object as a parameter to a method.
2) Accidentally creating a new variable.

I agree with number 1. I like duck typing and respect it, but I have
seriously thought of suggesting 'voluntary' type checks to Ruby before,
since it is a very common problem to pass a String instead of an
Integer.
I would have except I thought I might be bludgeoned by the community or
something. I still would use something like
def func_1(a ==> String, b ==> Fixnum)
end
if I had it. If only to ensure expected use at the beginning of coding
creation.
-Roger
 
E

Eivind Eklund

I agree with number 1. I like duck typing and respect it, but I have
seriously thought of suggesting 'voluntary' type checks to Ruby before,
since it is a very common problem to pass a String instead of an
Integer.
I would have except I thought I might be bludgeoned by the community or
something. I still would use something like
def func_1(a ==> String, b ==> Fixnum)
end
if I had it. If only to ensure expected use at the beginning of coding
creation.

Try out http://people.freebsd.org/~eivind/ruby/types/

It adds a fairly flexible syntax for doing these kinds of checks,
about as compact as the above. You can find out if they are useful to
you or not. (It also allows more appropriate type checks, like
respond_to?)

Eivind.
 
L

Lee Jarvis

Marc said:
About the missing end's, over time I kinda developed a habit of
knowing where I made an error and can fix it up quickly.
It is not really that problematic for me. HOWEVER, I would actually
not mind some magical per-file way to omit end's based on
indent. :>


I disagree, If you indent your code in the first place I find the
missing 'end's pretty easy to pick up. If you indent 2 spaces, pass a
block, backspace 2 and there is your end. I know it wouldn't be that
easy on larger applications, but the same idea still stands IMO. This
isn't Python.


So why not spend a couple of lines testing the object first?

This can happen a lot no matter what language you code, I don't think
setting up the equivilant to Perls 'strict' would be the way to go, in
my opinion. But hey, I'm nothing but a humble Ruby programmer. :)

Regards,
Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top