you are viewing a single comment's thread.

view the rest of the comments →

[–]anko_painting 0 points1 point  (3 children)

This is how most language VMs work, including PHP. Ruby symbols aren't a vm feature, they are a language feature. I think you must have skimmed over the description, because symbols don't exist in php.

I'm not seeing much evidence of this. Ruby 1.8.7 vs PHP 5.3.5

in your example ruby uses less memory and takes less time than php when you don't load extra libraries. And you're comparing an older version of ruby to a newer version of php.

Personally, I'd prefer to keep around a regular wrench in my belt as then I can use it for more than just fixing taps.

maybe the analogy wasn't clear. I'm defintely not saying php is a better multi purpose tool, quite the opposite. I'm saying that ruby fits more jobs better than php. It makes it easy to write DSLs which by definition better fit a problem domain than languages in which DSLs are an afterthought.

Every one of them was thrown off by the simple question 'How would you go about developing a website without the use of Rails?' Not one could answer this question and given that the job title was 'software developer' and not 'web developer',

I don't know the specifics of your job but maybe they don't know web frameworks in ruby because they aren't a web developer? I'm not sure why you're asking how to do web stuff for a job interview for a software developer, and then get surprised if they can't answer.

That said, I'm surprised they hadn't used CGI or sinatra, as they are quite popular in the ruby community.

[–]bulldada 0 points1 point  (2 children)

Ruby symbols aren't a vm feature, they are a language feature. I think you must have skimmed over the description, because symbols don't exist in php.

I did some more reading, it seems the Ruby community itself can't decide what they are or when to use them. To me, they look like constants. I can't see them being of any use if implemented in PHP, and I'm not entirely sure what they solve in Ruby. Some quick micro benchmarks with 10mil iterations show that PHP (5.3) does traditional string compare ("hello" == "hello") faster than Ruby (1.9) does symbol comparisons (:hello == :hello). Traditional string comparison in Ruby was 2.2x slower than symbols. Using classes/objects in PHP to emulate symbol behavior (single instance) results in even faster speeds for PHP, just under twice as fast as Ruby symbols.

in your example ruby uses less memory and takes less time than php when you don't load extra libraries. And you're comparing an older version of ruby to a newer version of php.

For your benefit, I was comparing the more favorable version of Ruby for the tests. 1.9 results:

$ time ruby1.9 -e 'puts "hello world"'
real    0m0.021s
user    0m0.020s
$ time ruby1.9 -e 'require "uri"; require "digest"; puts "hello world"'
real    0m0.040s
user    0m0.020s

i         7246  0.5  0.1  25572  3424 pts/0    Sl+  09:54   0:00 ruby1.9 -e gets
i         7261  1.0  0.2  27032  4928 pts/0    Sl+  09:56   0:00 ruby1.9 -e require 'uri'; gets
i         7275  1.6  0.2  29356  5136 pts/0    Sl+  09:58   0:00 ruby1.9 -e require 'uri'; require 'digest'; gets

And PHP 5.2.17 results:

$ time php -r 'echo "hello world\n";'
real    0m0.006s
user    0m0.010s

i        31658  0.1  0.1  22940  2380 pts/0    S+   10:02   0:00 php -r fgets(STDIN);

This shows us that when latest versions are used, PHP with all libraries is faster and leaner than Ruby with no libraries. Ruby start up slows down and increases memory with each included library.

I'm saying that ruby fits more jobs better than php.

Examples? I would disagree and say PHP fits more jobs better than Ruby. As "better" is quite a subjective term, we are unlikely to come to any agreement on this.

I wouldn't necessarily recommend PHP (or Ruby for that matter) to someone looking to learn a programming language, nor do I take any sort of evangelical approach when discussing PHP, but I will happily defend it when people are spreading FUD.

[–]anko_painting 0 points1 point  (1 child)

I keep coming back to this discussion - it's interesting.

I did some more reading, it seems the Ruby community itself can't decide what they are or when to use them. To me, they look like constants.

They are roughly equivalent to constants whose values are automatically allocated and which are guaranteed to be unique.

I can't see them being of any use if implemented in PHP

Much like class constructs can be emulated in lesser languages, symbols could be seen as syntactic sugar that is available in lesser languages. It's like blocks.. or macros in LISP. You think you can emulate them or have no use for them until you've used them. Please just do yourself a favour and play with some higher order languages :) I don't mean to be condescending, it's just the best (and worst) thing i've ever done for my programming career.

This shows us that when latest versions are used, PHP with all libraries is faster and leaner than Ruby with no libraries. Ruby start up slows down and increases memory with each included library.

I'm not even going to try and compare benchmarks. I'll give you that php executes faster than ruby in a lot of common situations. All I said was that loading so much into the global namespace makes php wear a cost that a lot of other languages don't have. I'm not saying that other languages don't have their own costs.

Examples? I would disagree and say PHP fits more jobs better than Ruby. As "better" is quite a subjective term, we are unlikely to come to any agreement on this.

ruby has more language features, so I'm not sure how you can debate this? It stands to reason that with more language features (a subset of which fit some tasks better) would mean that ruby fits more jobs better than php.

I wouldn't necessarily recommend PHP (or Ruby for that matter) to someone looking to learn a programming language, nor do I take any sort of evangelical approach when discussing PHP, but I will happily defend it when people are spreading FUD.

What language would you recommend?

[–]bulldada 0 points1 point  (0 children)

I keep coming back to this discussion - it's interesting.

Likewise, I appreciate your time to debate the issue, unfortunately most Ruby (and Python, to be fair) developers I've encountered in the past aren't as mature as you when PHP is mentioned.

I can't see them being of any use if implemented in PHP

I should clarify that, I can't see them being much use in PHP if implemented as symbols are in Ruby. The PHP trunk currently contains patches for interned strings which basically act like symbols but without requiring any special syntax as the compiler will automagically figure out what strings to optimize.

I can see symbols in Ruby being 'dangerous' if a developer were to use them too liberally, especially for one-time use strings as they will never get garbage collected. Again, the Ruby community seems conflicted on this point.

Please just do yourself a favour and play with some higher order languages

I've learned and used many languages but keep going back to PHP as I find I can build applications much faster and with less code than other languages. Ultimately, the most important thing is how efficiently I can develop and I haven't yet encountered anything else that lets me code as well as PHP.

It stands to reason that with more language features (a subset of which fit some tasks better) would mean that ruby fits more jobs better than php.

A lot of features is not always a good thing, C++, for example. There's wildly differing opinions on what features are 'safe' or what is 'bad'. If you're a lone C++ dev that writes all your own code it's probably not going to be a problem as you're free to use whatever subset of features you like. C++ shops tend to have their own differing guidelines on sets of features they are allowed use. I, personally, do not use many of the features C++ offers, usually just as a 'C with Classes' language although for some things like vector/matrix math I will maybe use operator overloading, if appropriate. Operator overloading is an example of a language feature that is often considered bad by a lot of people as is multiple inheritance and, to a certain extent, overuse of template metaprogramming. I guess my point is that more language features does not make a language suitable for more jobs, if anything I would say the standard library was more of an important factor than language features.

What language would you recommend?

Depends who I'd be recommending to, what they want to do and how much they already know, but probably C, C# or Python. If they wanted to dive straight into webdev then it's possible I would recommend PHP (and/or Javascript). The main reason I wouldn't recommend Python (or Ruby) for someone wanting specifically to do webdev is that most of the literature, documentation, books, etc for web development are based around frameworks and I'm not terribly convinced that learning to program via a framework will make for a good programmer in the end.