SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 174
-
Jul 22, 2005, 05:17 #26
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also, not very healthy to have such an oppinion towards the world's most used enterprise language.
I don't use it day to day but I have used it for a short period in the past, and it's like a whole religion in it's own right.
Worship it
-
Jul 22, 2005, 05:33 #27
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ryan Wray
Code:class Object alias is_a instance_of? end if someone.is_a Person then puts someone.name end
Code:if(!input.isValid) return false;
Code:return false unless input.isValid
-
Jul 22, 2005, 06:15 #28
- Join Date
- Jul 2005
- Posts
- 194
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In ruby, you are not tied to one particular coding style, you can always use more verbose control stucture, if you want. And any core method can be redefined, renamed or extended at any time:
-
Jul 22, 2005, 07:22 #29
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, as said it's a matter of taste and habit. Imagine there are people who find this nice, readable and transparent:
Code:(defmethod Concat ((L1 list) (S1 string)) (Concat (apply #'concatenate 'string (mapcar #'princ-to-string L1)) S1))
-
Jul 22, 2005, 07:50 #30
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- Posts
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I do see what people are getting at with Ruby's readablity. It does take getting used to as the syntax is quite different from mainstram languages. Once you get used to it, it can be very powerful and you can do very short code. The example with instance of here is not a good example. The ablity to have more than one way to skin a cat in Ruby is probably the biggest thing setting it apart from Python. I guess the way code reads in Ruby is like whitespace in python, you love it or hate it and normally if you use the language enough you generally grow to like it
-
Jul 22, 2005, 08:48 #31
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The ablity to have more than one way to skin a cat in Ruby is probably the biggest thing setting it apart from Python.
That is much like using object oriented programming mixed with procedural programming, which isn't very smart is it now... You have one half of an application designed beutifully with OOP, and then you go and screw it all up with prodecural programming.
That is much like what your talking about with a languages variable syntax in my view. Yuk
-
Jul 22, 2005, 09:19 #32
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The ablity to have more than one way to skin a cat in Ruby is probably the biggest thing setting it apart from Python.
One problem with your claim: If you have more than 1 way to do a thing with the language syntax, how can Ruby's pride lay in "the priciple of least surprise" ? The Perl heritage is actually a bad thing IMO. Python is more elegant from this point of view.
-
Jul 22, 2005, 09:45 #33
Originally Posted by Ryan Wray
Point 2...I like the convention of adding ? to boolean methods. Again, its a matter of taste, and whilst you probably can't escape it when using the standard library, there isn't anything that says you have to use the convention in your own modules (I think...somebody correct me if I'm wrong).
-
Jul 22, 2005, 10:08 #34
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- Posts
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
-
Jul 23, 2005, 09:49 #35
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
I actually wasn't really complaining about Ruby's readibility, but rather I found the Ruby example provided was not more readable than the PHP one. It was more readable than the C++ one. I know many languages, at least to the point of reading them and implementing basic control structures, statements, etc. Hence, how I read something is not limited to any particular language. I think my first point was a very good point. When programming, we think in a sequential state. I think my second point was valid too.
puts person.name if person.instance_of? Person
puts person.name if person.instance_of Person? -- The question is not complete until after the class 'Person'. It is not a question like this: If person is an instance of? Person.
I did mention I may be biased, but do you mind telling me why the statement was highly inaccurate. Are my points valid? If I am highly inaccurate, then so is anyone who says Ruby is more readable.
-
Jul 23, 2005, 10:27 #36
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- Posts
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If you want to agrue about reabablity, then have a look at
Code:def duration_as_text(duration_secs) case duration_secs when 0 then "0 seconds" when SECOND then "#{duration_secs/SECOND} second" when SECOND+1..MINUTE-1 then "#{duration_secs/SECOND} seconds" when MINUTE..2*MINUTE-1 then "#{duration_secs/MINUTE} minute" when 2*MINUTE..HOUR-1 then "#{duration_secs/MINUTE} minutes" when HOUR..2*HOUR-1 then "#{duration_secs/HOUR} hour" when 2*HOUR..DAY-1 then "#{duration_secs/HOUR} hours" when DAY..2*DAY-1 then "#{duration_secs/DAY} day" when 2*DAY..WEEK-1 then "#{duration_secs/DAY} days" when WEEK..2*WEEK-1 then "#{duration_secs/WEEK} week" when 2*WEEK..MONTH-1 then "#{duration_secs/WEEK} weeks" when MONTH..2*MONTH-1 then "#{duration_secs/MONTH} month" when 2*MONTH..YEAR-1 then "#{duration_secs/MONTH} months" when YEAR..2*YEAR-1 then "#{duration_secs/YEAR} year" else "#{duration_secs/YEAR} years" end end
I do agree with bonefry, Java style namespaces is not what PHP really needs, but rather modules + mixins like Ruby or however Python does them. PHP is going totally down the wrong route by copying Java for everything, such as using static typing and binding, which are totally counter-constructive in web applications, not to mention Java is a butt ugly as hell really with all the C/C++ style typing and casting all over the place.
-
Jul 23, 2005, 10:52 #37
For those not familiar with ruby syntax, the two dots are the range operator, the #{} in the strings evaluates the expression between the curly braces, and methods return the value of the last expresion executed (although you can explicitely return if you want to)...
As for punctuation in method names, I think it's great; along with using the ? for methods that return booleans, another convention is to use a ! after methods that modify their arguments.
-
Jul 23, 2005, 11:52 #38
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ryan Wray
-
Jul 23, 2005, 14:34 #39
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi.
Off topic first...
This is pure opinion (and yes I also come from a C++ background, but also a Perl background), but I think that PHP is more readable than Ruby. Does someone want to hold a quick poll on the topic? That would put the issue to bed.
Back to PHP namespaces...
What does the patch look like in practice? What sort of code do you write with the namespace patch?
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Jul 23, 2005, 16:33 #40
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- Posts
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I do agree with Marcus that in the end it boils down to opinion. Cerainly some things in PHP are more readable, but at the same time are more tedious to write, which is probably why I favour Ruby as I'm a lazy person who can't type more than 30 wp/m
All I can say is that C++ and PERL are two of the worlds most *unreadable* languages(generalisation before anyone decides to joke and mention languages like "whitespace"). The only realistic exception is ASM
As for the name space patch, all I remember was there was some discussion on the internals mailing list about this. It could mean there's a off chance that it will make it into the 5.2 branch
-
Jul 23, 2005, 17:33 #41
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by lastcraft
basic:
class1.php
PHP Code:namespace ns
{
class class1
{
public $mem1 = 1;
}
}
class3.php
PHP Code:namespace ns
{
private class class3
{
public $mem3 = 3;
public static function staticFunc()
{
echo "static called\n";
}
}
}
PHP Code:require_once( dirname( __FILE__ ) . '/class3.php' );
namespace ns
{
class class3_child extends ns:class3
{
function printValue()
{
echo $this->mem3, "\n";
}
function callStatic()
{
class3::staticFunc();
}
}
}
As for PHP vs Ruby... well, I don't like curly brackets, mandatory semi colons, and '$this->' * 100. Guess which one I like more
DouglasHello World
-
Jul 23, 2005, 17:43 #42
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Dr Livingston
I don't know how anyone can complain about using an @@ prefix for class variables when PHP needs a $ before every variable, and $this-> before every instance variable.
Later,
DouglasHello World
-
Jul 23, 2005, 17:50 #43
- Join Date
- Jul 2005
- Posts
- 194
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by MiiJaySung
-
Jul 24, 2005, 04:43 #44
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
Originally Posted by DougBTX
Namespaces means that I can import a library and in so doing change the public API. It's about preventing nameclashes. What's all this "private class" nonsense (the "private" keyword should have been killed off at the Java stage anyway, but I digress)?
I want something like this...
PHP Code:require_once_in('a_library.php', 'A');
require_once_in('a_library.php', 'B');
$a = new A:Thing();
$b = new B:Thing();
PHP Code:require_once_in('simpletest/reporter.php', 'SimpleTest');
class HtmlReporter extends SimpleTest:HtmlReporter { ... }
I doubt that this would have been hard to implement (there is no need for nested namespaces for example) and everything is done at parsing time so the performance hit is zero.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Jul 24, 2005, 06:38 #45
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
Oh well, I'll let this get back to a discussion of name-space support in PHP, not Ruby readibility vs. PHP readibility.
-
Jul 24, 2005, 06:43 #46
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by wdeboer
*cleaner: using less code to do the same thing with the same or better readability. (I'd be surprised if someone didn't understand that duration_as_text returned a string, even though there is no explicit return.)
Later,
DouglasHello World
-
Jul 24, 2005, 08:16 #47
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by DougBTX
a = b + c
that's not clean, that's dangerous. Clean is when it's your code, or when you trust the programmer who did it like you trust God.
-
Jul 24, 2005, 08:43 #48
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Clean as in neat and tidy, and at best, elegant.
Hello World
-
Jul 24, 2005, 08:59 #49
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:def duration_as_text(duration_secs) case duration_secs when 0 then "0 seconds" when SECOND then "#{duration_secs/SECOND} second" when SECOND+1..MINUTE-1 then "#{duration_secs/SECOND} seconds" when MINUTE..2*MINUTE-1 then "#{duration_secs/MINUTE} minute" when 2*MINUTE..HOUR-1 then "#{duration_secs/MINUTE} minutes" when HOUR..2*HOUR-1 then "#{duration_secs/HOUR} hour" when 2*HOUR..DAY-1 then "#{duration_secs/HOUR} hours" when DAY..2*DAY-1 then "#{duration_secs/DAY} day" when 2*DAY..WEEK-1 then "#{duration_secs/DAY} days" when WEEK..2*WEEK-1 then "#{duration_secs/WEEK} week" when 2*WEEK..MONTH-1 then "#{duration_secs/WEEK} weeks" when MONTH..2*MONTH-1 then "#{duration_secs/MONTH} month" when 2*MONTH..YEAR-1 then "#{duration_secs/MONTH} months" when YEAR..2*YEAR-1 then "#{duration_secs/YEAR} year" else "#{duration_secs/YEAR} years" end end
) to work out the about with a simple mathematical formula? Isn't that what Mathematics is all about
That's not namespaces, that's packages! Oh, joy, they cannot even get that right.
PHP Code:class HtmlReporter extends SimpleTest:HtmlReporter { ... }
does that count as a cup of coffee?
-
Jul 24, 2005, 10:58 #50
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Dr Livingston
Actually, it is a real question. I wish Ruby could make a cup of coffee. The VM isn't there yet, still too slow and too big for embedding in a coffee machine. I think someone did get it running on a PDA though, which is heading in the right direction.
DouglasHello World
Bookmarks