Ruby could be wildly more popular if it had ...

C

Chris Thomas

But then you get some larger ones:

set.map { |e|
if something
e.x
else
e.y
end
}

[Robert:]
Know your ternary operator: :)
set.map { |e| something ? e.x : e.y }


I know my ternary operator, but:
- in my code snippet, "something", "e.x", and "e.y" were placeholders
for something far bigger than you or I could imagine
- sometimes there is multi-part processing do be done before arriving
the "return value" for the block

Also
- The ternary operator is idiomatic of expert (or expert-wannabe) use
of the C family of languages and likely to confuse and even scare away
novice Ruby users who aren't from that segment of the population, or
only have limited experience with C.

Chris
 
R

Robert Klemme

Chris Thomas said:
Also
- The ternary operator is idiomatic of expert (or expert-wannabe) use
of the C family of languages and likely to confuse and even scare away
novice Ruby users who aren't from that segment of the population, or
only have limited experience with C.

That's possibly true. I faintly remember the times when I first saw ?:
and wondered what that might be. Nowadays I've become so acquainted with
this idom that I hardly notice this as something strange. Thanks for
reminding me!

Regards

robert
 
M

Marko Schulz

The ternary operator is *useful*, as evidenced by the fact that people
use it when equivalents exist.

???
Violence is *useful*, as evidenced by the fact that people
use it when equivalents exist.
???
 
X

Xiangrong Fang

The beauty of ruby is its tolerance. I use delphi heavily, also Java
Javascript and C. Everything works fine in Ruby. No surprise at all.

Ruby is pragmatic programming language. Don't even think about grammar.

If you hate ternary, simply don't use it.
 
J

Josef 'Jupp' Schugt

Saluton!

* Marko Schulz; 2003-08-01, 12:37 UTC:
???
Violence is *useful*, as evidenced by the fact that people
use it when equivalents exist.
???

Correct. The question is if being useful makes it acceptable. Some
people believe that a goal can justify any means while others believe
that this is not true.

I am pretty sure that there is an equivalent of German 'Der Zweck
heiligt die Mittel' in many languages...

Gis,

Josef 'Jupp' Schugt
 
J

Josef 'Jupp' Schugt

Saluton!

* Austin Ziegler; 2003-08-02, 21:17 UTC:
"The End Justifies the Means", in English.

I disagree with it, believing that the means can corrupt the end.

Obviously even the UN Security Council does not share your (and mine)
opinion. They guarantee that a well-known country's troops may commit
any crime of war without being punished for it by the international
community. I don't think that they are going to commit such crimes
but that does not change the ethical implications of the decision.

Gis,

Josef 'Jupp' Schugt
 
J

Josef 'Jupp' Schugt

Saluton!

* Michael Garriss; 2003-08-03, 17:39 UTC:
Could you take this discussion off the list please.

Sorry ... I just wanted to point out that different opinions exist
even on that subject.

As far as the use of parentheses in Ruby are concerned I don't see a
necessity to add more of them to Ruby's syntax. If one really wants
to use lots of them this is already possible, if one wants to avoid
them as far as possible this is also feasible. One should note that
one can easily avoid parentheses in C by means of two almost trivial
preprocessor defines:

#define begin {
#define end }

int main(int argc, char **argv)
begin
if (argc < 2)
begin
return -1;
end
else
begin
return argc-1;
end
end

The result is some new programming language - it's no longer C (one
should keep in mind that C++ started as C preprocessor macros).

Adding new parentheses to Ruby would result in something similar:
'Ruby--'

Gis,

Josef 'Jupp' Schugt
 
B

Brian Candler

One should note that
one can easily avoid parentheses in C by means of two almost trivial
preprocessor defines:

#define begin {
#define end }

But then they are just 3-5 character parentheses, not 1-character
parentheses...
int main(int argc, char **argv)
begin
if (argc < 2)
begin
return -1;
end
else
begin
return argc-1;
end
end

Actually all those apart from the first 'begin' and the final 'end' are not
necessary in C.

Cheers,

Brian.
 
R

Robert Klemme

Josef 'Jupp' Schugt said:
#define begin {
#define end }

int main(int argc, char **argv)
begin
if (argc < 2)
begin
return -1;
end
else
begin
return argc-1;
end
end

int main(int argc, char **argv) {
return argc < 2 ? -1 : argc-1;
}

(I love that ternary operator... :))
The result is some new programming language - it's no longer C (one
should keep in mind that C++ started as C preprocessor macros).

Not 100% correct, AFAIK. C++ started out as a precompiler that spat out C
code. CPP macros are by far not powerful enough to implement C++ on top
of C. Just think of the management of inheritance hierarchies.

Regards

robert
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top