The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

This may look strange at first, but IMO it's cleaner. You don't need semicolons ( ; ), no braces ({ and } and ( and )), . instead of ->

umm, pardon but these two are same except that in Ruby code there's no curly braces & semicolons & you use boring periods(.) instead of stylish arrows(->)!! But you can use semicolons in Ruby if you want to, when you want to have more than 1 statement on a single line. I find this comforting as semicolons make code more readable by telling user where a line ends!! But I don't like the periods for referring to object methods!! Its the one thing that I hated in VB & Java & C++ & arrows were the only thing I liked in Perl & what attracted me to PHP, they are kinda informative by telling you visually that the control is flowing from left to right, first object is called & then function is referenced. And mind you, braces help define a code block, I missed them a lot in VB!!

Originally Posted by Fenrir2

PHP:

PHP Code:

for($i = 0; $i < 10; $i++){print("hi!");}

Ruby:

Code:

10.times { print "hi!" }

And that brings us to readability. The Ruby version actually reads like normal english. PHP is cryptic.

Yes, this is certainly better in Ruby, its more readable, like in VB. And ofcourse, Rails take Ruby's readability/simplicity further ahead!!

umm, pardon but these two are same except that in Ruby code there's no curly braces & semicolons & you use boring periods(.) instead of stylish arrows(->)!! But you can use semicolons in Ruby if you want to, when you want to have more than 1 statement on a single line. I find this comforting as semicolons make code more readable by telling user where a line ends!! But I don't like the periods for referring to object methods!! Its the one thing that I hated in VB & Java & C++ & arrows were the only thing I liked in Perl & what attracted me to PHP, they are kinda informative by telling you visually that the control is flowing from left to right, first object is called & then function is referenced. And mind you, braces help define a code block, I missed them a lot in VB!!

FYI, ASP.NET is just a subset of the .NET framework, one which expands the reach of .NET to the web. ASP.NET depends on .NET, not vice versa!! There are a lot of .NET programmers who use VB.NET/C# & I've even met some VC++.NET dudes who don't program for the web but for desktop applications!!

FYI ASP.NET was the reason for .NET's success not viceversa. The vast majority of Windows programmers are just happy with VC++ 6 and VB 6 because .NET is not available by default in windows XP. And you completelly missed my point. I am quite familiar with ASP.NET to know it's purpose, thank you very much.

asp_funda, control is flowing from right to left. You are sending a message to an object. Notice how that sentence reads? The first part is "send a message" the second part is "to an object."

If you want syntax to describe control flow it should look like object<-method.

Ok, I goofed up, hang me!!

Originally Posted by KTottE

Or if you want to be cool, use Befunge.

Are you talking about this? If yes, then ofcourse I'll try it if using that can get me a gorgeous chick!!

Originally Posted by sweatje

Okay, how about this instead for less PHP like code

Ruby:

Code:

obj.do_somthing if obj.is_somthing?

yeah that's cool as well. Mind ya, I'm not saying that Ruby ain't cool or easy, what I said was the things that I don't quite like or miss in Ruby!! But then, nothing has everything.

Originally Posted by bonefry

FYI ASP.NET was the reason for .NET's success not viceversa. The vast majority of Windows programmers are just happy with VC++ 6 and VB 6 because .NET is not available by default in windows XP.

Off Topic:

right, you mean to say that these programmers don't ever compile any DLLs etc that they need to install on client PCs that'll run their software & they use only those DLLs that are available in Windows??? If that's not the case then is it a big deal packaging the .NET runtime in the installer?? We've done it loads of times, but ofcourse if you are giving away software as a web download, then you gotta think twice, bandwidth ain't cheap!!

Originally Posted by bonefry

And you completelly missed my point. I am quite familiar with ASP.NET to know it's purpose, thank you very much.

Off Topic:

Thanks for telling me that, I thought you didn't know ASP from .NET!! Do me a favour & don't reply to my posts, as you can't bother to read them correctly & get the right meaning!! And to say nothing of the fact that from your posts here, all I've seen is that more than half the time, you don't know what you are talking!!

Thanks for telling me that, I thought you didn't know ASP from .NET!! Do me a favour & don't reply to my posts, as you can't bother to read them correctly & get the right meaning!! And to say nothing of the fact that from your posts here, all I've seen is that more than half the time, you don't know what you are talking!!

Please tell me what is this all about. What have I said that offended you without reason and were are those posts were I don't know what I'm talking ?

There is a difference between (4..99) and (4...99), that's one thing I do not like.

Second, things like that and also things like 99.times { ... } don't really add nothing but performance problems. And 99.times it's not even OOP (dare I say it) because the method "times" doesn't have anything to do with an Integer.

Of course times is related to an integer. Its another word for multiply, and what can you do with integers? Multiply things by them. Ruby just happens to let you multiply more than just other integers/numeric objects.

Also, I'm not sure what the problem is with the range notation, other than perhaps that it is a little bit obscure.

I'm not too sure how either of the above causes performance problems either. What exactly do you mean?

this is ironic... a friend showed me ruby today and I was reading alot about it, and am even considering switching to it and stop developing in php but rather ruby.
I then get on the boards and find this post lol.

Anyways, for anyone interested in understanding what it is better, u may want to watch the movie on their site where they make a blog in 15 minutes. It's impressive, but I found 2 issues about it.
1) I'd have to learn it from scratch, wasnt like php where 70% of the code was just like c++.
2) If I wanted to add customized coding, like cron jobs that do very minute things, it seems harder to do with ruby rather than with php

Anyways, for anyone interested in understanding what it is better, u may want to watch the movie on their site where they make a blog in 15 minutes. It's impressive, but I found 2 issues about it.
1) I'd have to learn it from scratch, wasnt like php where 70% of the code was just like c++.
2) If I wanted to add customized coding, like cron jobs that do very minute things, it seems harder to do with ruby rather than with php

Actually, another amazing thing about ruby is that it's a chameleon. Braces, semicolons and much more are optional.

Just because you can write:

Code:

arr.each{ |p| puts p.title } unless array.empty?

Doesn't mean you can't write:

Code:

for (p in arr){
puts(p.title);
}

2. Says who? Many times it's easier. The fact that a particular task is smaller or is a cron job has no bearing on the langauge/framework/etc.

I think the continuing success of Rails, and many a Java framework, not to mention .NET, proves there is certainly a need for a framework.

Nah, it proves that there is a desire[ for a framework in those languages.

So why should PHP be any different?

Because it's a different language with different features? Who's to say that any way is better than the others? There are still tons of successful apps out there that get by without a framework, in plenty of languages (not just PHP). The most successful projects that I can think of (open source or otherwise) don't really use a "framework" in the sense that we're talking about frameworks anyway.

People aren't going to switch to another language en masse just because it has a nice framework. Some might. Others won't. It's really a silly argument.

My definition of a killer framework is a framework popular and good enough to attract people to use it's underlying language and platform. And that's what Zope and Rails are. And that's what PHP lacks. How many on this forum have been attracted to PHP because of PHP.MVC or Horde or Prado or .... ?

That's a pretty strict definition. I think it speaks volumes of Ruby that nobody gave a damn about it UNTIL there was a good framework for it. People have been flocking to PHP in ever-growing numbers for years without it. Does this mean that PHP is that much of a superior language to Ruby? Of course not. That's just dumb.

And what would .NET be without ASP.NET ?

C#, Visual Basic, and C++?

Originally Posted by Fenrir2

@Skyblaze: Could you please stop saying stupid things? How many lines of Ruby-code have you written? So please use Ruby & Ruby on Rails before talking about it.
Ontopic:

I will compare Ruby to PHP based on my experience:

Ruby is focused on OOP, PHP on procedural code. I prefer OOP. Ruby doesn't have a clumsy syntax like:

PHP Code:

if($obj->is_something())
{
$obj->do_something();
}

Ruby:

Code:

if obj.is_something?
obj.do_something
end

This may look strange at first, but IMO it's cleaner. You don't need semicolons (, no braces ({ and } and ( and )), . instead of ->, and it's common to add a question mark to methods like is_something or has_something => is_something?

PHP:

PHP Code:

for($i = 0; $i < 10; $i++)
{
print("hi!");
}

Ruby:

Code:

10.times { print "hi!" }

And that brings us to readability. The Ruby version actually reads like normal english. PHP is cryptic.

Just give Ruby a try, and you'll find out it's much easier (so you can focus on the real problem), and much more fun!

1.) What? They're practically identical. (and why aren't you using the instanceof operator? And I can simpify both into 1 line constructs anyway.

2.) Most major languages use semicolons to end lines and curly braces (C, C++, Java, C#, Javascript, etc.). Which makes this syntax MORE natural to the average programmer who has any level of experience.

I agree that the -> operator is clumsy compared to the ., but for someone with a C or C++ background, it's second-nature (it's the pointer member accessor, whereas the period only works on regular variables).

1) Just because you can write it on one line doesn't mean you should.
2) This is optional in Ruby, if you feel like doing it: Do it.

Objects in Ruby are always references, and if you have a C++ background then you would know that you access reference data members and methods with the dot operator.

3) In the second post of this thread I gave two very quick examples of Ruby and PHP (since PHP was what the original poster referenced) and asked which he felt was more natural. The same question still stands, if you think echo str_repeat('hi', 10); feels more natural than 10.times {puts 'hi'} then fine, don't use Ruby. Actually, you could write the first thing in Ruby if you just wrote the echo and str_repeat methods yourself and added them to the Object class.

PHP Code:

class Object
def echo(msg)
puts msg
end

def str_repeat(msg, num)
ret_arr = Array.new

num.times { ret_arr.push(msg) }

return ret_arr.join
end

end

echo str_repeat( 'hi', 10);

Are you happy now?

If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
- Shantideva

Of course times is related to an integer. Its another word for multiply, and what can you do with integers? Multiply things by them. Ruby just happens to let you multiply more than just other integers/numeric objects ... I'm not too sure how either of the above causes performance problems either. What exactly do you mean?

How can times be another word for multiply ? Maybe in your vocabulary but not in ruby. In ruby it's a word for "repeat it this many times" and it's not related to an integer.

In the current version of Ruby it doesn't cause performance problems because it's a slow interpreter anyway, but when it will be optimized a little, you will see. Of course it has performance issues. The code block is a function that gets called on every iteration. And function calls are slow. Also, the iteration itself is also a function that increments the internal counter, so that again, is slower that manually writting var = var + 1. And it doesn't matter for 30 or 100 iterations, but what about 1.000.000 ?

Originally Posted by Luke Redpath

Nah, it proves that there is a desire[ for a framework in those languages.

We are long gone since the MS-DOS days when knowing some assembly language + C or Pascal (which were both very high languages) made one a good programmer. You can no longer work without APIs. Not even in PHP - in case you haven't noticed, the standard library keeps growing in PHP 5.1 (for example with the addition of PDO) and it will grow further in PHP 6.

Originally Posted by Luke Redpath

That's a pretty strict definition. I think it speaks volumes of Ruby that nobody gave a damn about it UNTIL there was a good framework for it. ... That's just dumb.

Of course not. Who ever said that again ?

Originally Posted by Luke Redpath

And what would .NET be without ASP.NET ?
C#, Visual Basic, and C++?

I'm not sure what your point was ... but maybe I was not clear enough
Please give me one good reason why .NET was succesfull other than ASP.NET.
To make a quick summary: many Windows programmers still use old technologies because .NET is not available in WinXP by default, and to answer to someone else - it has huge issues in Win9X (which is still in use). And it was marketed as the perfect choice for web services. But recent surveys show that Java is still the preferred choice. Is there something else besides ASP.NET that made .NET succesfull ?

bonefry, "times" is a commonly used word for multiplication. "Five times two equals ten" and so forth.

However, this doesn't work in Ruby, because to be semantically correct 5.times 2 should output 10, and it doesn't. It responds with a syntax error (times accepts a block as a parameter). So, you are both correct.

Anyway, performance issues related with calling a function once per iteration is not exclusive to Ruby. The following two snippets would be equally (in)efficient:

PHP Code:

10.times do
some_method
end

for ($i = 0; $i < 10; $i++)
{
some_method();
}

If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
- Shantideva

My definition of a killer framework is a framework popular and good enough to attract people to use it's underlying language and platform. And that's what Zope and Rails are. And that's what PHP lacks. How many on this forum have been attracted to PHP because of PHP.MVC or Horde or Prado or .... ?

1) Just because you can write it on one line doesn't mean you should.
2) This is optional in Ruby, if you feel like doing it: Do it.

Objects in Ruby are always references, and if you have a C++ background then you would know that you access reference data members and methods with the dot operator.

3) In the second post of this thread I gave two very quick examples of Ruby and PHP (since PHP was what the original poster referenced) and asked which he felt was more natural. The same question still stands, if you think echo str_repeat('hi', 10); feels more natural than 10.times {puts 'hi'} then fine, don't use Ruby. Actually, you could write the first thing in Ruby if you just wrote the echo and str_repeat methods yourself and added them to the Object class.

PHP Code:

class Object
def echo(msg)
puts msg
end

def str_repeat(msg, num)
ret_arr = Array.new

num.times { ret_arr.push(msg) }

return ret_arr.join
end

end

echo str_repeat( 'hi', 10);

Are you happy now?

I think you completely missed the point. It's not that you can / can't do something in Ruby / PHP, it's that you can do anything in either language and the argument of one being naturally superior is just downright stupid (ESPECIALLY when it comes to claims about being able to write shorter code). Claiming that something is easier to do in ruby because you pull out some arbitrary one line example is just plain idiocy. I can name a million things that I can do in one language that I can't do in another, but ultimately it doesn't matter, because I can still achieve the same results.

Does anyone actually have any real statistical data to show that any given language is "more productive" than any other? I sincerely doubt there's anything other than anecdotal.

Please give me one good reason why .NET was succesfull other than ASP.NET.

I gave you 3. C# is extremely popular, and is now the language of choice for windows desktop development. I see more openings for C# and VB.Net developers on monster than ASP.Net.

To make a quick summary: many Windows programmers still use old technologies because .NET is not available in WinXP by default,

True, but the msi installer will automatically install it when you install the program anyway, so what does it matter. Not only that, but there is no Java runtime installed by Windows XP by default either.

Oh, and actually all newer versions of XP that ship DO have the .Net framework preinstalled. It was a part of service pack 2, and any copies that shipped with that pre-loaded will have it. Those users still don't have java installed, though.

I've yet to encounter a single common windows application that uses Java, but I'm running 3 right now that use .Net. I haven't even installed a JRE on any of my desktops in years.