r/programming • • Feb 24 '13

Ruby 2.0.0

http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/
600 Upvotes

193 comments sorted by

View all comments

0

u/jokubolakis Feb 24 '13

Can someone explain to a non-programmer what's new and what's ruby for?

18

u/TikiTDO Feb 24 '13

Ruby is a programming language used for a very wide variety of tasks. Probably the most popular framework written in ruby is "rails" which is a platform for making complex web pages. Because what ruby is, it would be rather hard to explain the changes and why they're cool to a non-programmer; basically it's faster, it handles resources more intelligently, and it lets people do a bunch of things they've been asking for more easily.

3

u/[deleted] Feb 24 '13

Rails isn't really for web pages, but websites. The difference being that it helps you build all of the infrastructure behind the web pages.

3

u/hak8or Feb 24 '13

By more complex, are you referring to more dynamic pages? Why would I use Ruby over PHP/HTML/CSS/JS? Does Ruby essentially combine what I listed before into one language?

11

u/[deleted] Feb 24 '13

Ruby would replace PHP out of that list, not any of the others. For information on why what is different with Ruby over PHP then check out this page.

4

u/TikiTDO Feb 24 '13

In fact going further, there are projects written in ruby that help with the authoring of HTML, CSS and JS, sometimes with the help of other languages and tools. These can make life very easy when properly configured. For instance, instead of writing HTML, I could write slim and then have a ruby script translate that into HTML. Or I could write Sass and have ruby send my file to the sass parser in order to generate valid CSS without me having to do anything extra. Or even CoffeeScript instead of JS.

So in some respects, ruby can, if not directly replace, at least give you the option to hand off your code to other authoring tools.

3

u/[deleted] Feb 24 '13

To be fair, you can do exactly the same with PHP although it isn't as prevalent as with Ruby because as PHP applications are just deployed directly into a public web server directory it isn't easy to hide files that the user doesn't need to access.

1

u/[deleted] Feb 24 '13

What wasn't mentioned was the server that runs PHP, which is typically apache. Ruby also manages the HTTP server as well, correct? I.e. no need for apache.

4

u/[deleted] Feb 24 '13

No. Rails ships with a built in web server called WebBrick. Ruby does not. PHP 5.3 ships with a built in web server too. Neither of the servers included with PHP or Rails are intended for production usage. To serve up a rails app you typically use either apache (with passenger aka mod_ruby similar to mod_php for apache), or a dedicated server for ruby rack apps (unicorn, thin, rainbows, mongrel, etc etc).

5

u/thoomfish Feb 24 '13

WEBrick is part of the Ruby standard library, not part of Rails.

1

u/tardmrr Feb 24 '13

There are servers written in ruby, but you still need one (i.e. it isn't built into the language).

4

u/bjmiller Feb 24 '13

I can't think of a single reason to choose PHP over Ruby for a new project in any domain. Only if you already have an entrenched PHP application like MediaWiki or Wordpress would it make sense to use PHP.

If you want dynamic web pages then you need to target the client. Ruby and PHP are server-side languages and will not help you. Look at AngularJS for a modern client-side framework. If you don't like Javascript syntax then look at Coffeescript also.

-5

u/[deleted] Feb 24 '13

Ruby, I should mention, is a real programming language, whereas PHP can only be used for dynamic pages and is usually just embedded into HTML. You can do this with Ruby too of course. You can create native programs (weasel word, but compiles to bytecode and similar things probably don't mean much to you).

In web programming, Ruby is often used as the backend for dynamic web sites in lieu of say, ASP.NET, Java EE or PHP (or Python, in Reddit's case).

Why? because Ruby is a really, really nice language! I haven't been as productive with other languages as I have with Ruby. And that goes for a lot of other people, too.

If you want to get started with programming, Ruby is probably your best bet. I'd highly recommend the TryRuby tutorial by Code School. Codecademy also offers 'learning by doing' exercises, though you have to sign up (it's completely free though, unlike Code School's more advanced exercises). Otherwise, pick up a good book on it. Your local library should have one, Ruby is one of the top ten programming languages for a reason (hint: it's awesome!).

10

u/TikiTDO Feb 24 '13 edited Feb 24 '13

Now let's note get carried away here. PHP has a perfectly capable standalone interpreter which allows you to do anything you would want in a scripting language. I've written some threading server apps in PHP for the hell of it, and my only complaints there were syntax related. There are even tools to compile PHP to bytecode.

Ruby is great if you want a language that's pretty simple to pick up, without too many caveats until you get really deep into the guts of the environment. It's not the most efficient language out there, but with support for C plugins even that can be addressed for most situations. I wouldn't use it for very performance critical operations, but it's a good choice for general coding, and particularly good for prototyping.

4

u/[deleted] Feb 24 '13

I've written some threading server apps in PHP

Is any of your code publically available? I'd be curious to see how that works.

1

u/TikiTDO Feb 24 '13 edited Feb 24 '13

I'll see if I can find it, but this was a small proof of concept project I did years ago just to see if it was possible (Open multiple connections, then echo text typed in one to all the others), so it's probably in some archive in a deep corner of my backup drive.

More specifically, the program was actually multi-process, not multi-threaded. I remember abusing shared memory, and generally doing things that most would not associate with PHP in order to overcome the limitations of the language. I also recall that I had a busy loop for some reason, and that the server broke my networking if I didn't shut it down properly, though that was just me being lazy with connection management. These days I think they've implemented proper native threading in PHP, so I imagine you could do what I did back then with significantly less hackery.

2

u/[deleted] Feb 24 '13

These days I think they've implemented proper native threading in PHP

That's the part I'm interested in. I didn't think it was possible to do true multithreading in PHP.

1

u/TikiTDO Feb 24 '13

Take a look at PHP pthread.

1

u/[deleted] Feb 24 '13

Unfortunately, pthread is POSIX-only so you can't use it if you want your code to be portable to non-POSIX operating systems (i.e. Windows).

→ More replies (0)
→ More replies (1)

5

u/[deleted] Feb 24 '13

Ruby, I should mention, is a real programming language, whereas PHP can only be used for dynamic pages and is usually just embedded into HTML.

You're getting downvoted here because this is just patently false... As much as I love and prefer Ruby over PHP, there is absolutely nothing you can do with Ruby that you can't do in PHP. They are both capable languages that can be embedded into HTML or used to write complicated web applications using MVC principles. You can argue all day long about which has better performance, better syntax, better libraries, better tools, better community, but at the end of the day saying one is a real programming language and the other is not is just ridiculous.

1

u/[deleted] Feb 24 '13

PHP is only for dynamic pages in practice; in theory, there is nothing to stop you using it for anything else.

For example plenty of web developers use PHP for command line scripts, such as for generating the boiler plate for a new website. There are also bindings for things like GTK, so you could build GUI apps with PHP.

0

u/hak8or Feb 24 '13

I am already familiar with C, assembly, Python, and I dabble in HTML, Javascript, a TINY in PHP, and some CSS if that can be called a programming language. By native programs, you mean that Ruby can compile to the X86 architecture and both for the Windows and Linux os's?

Though, I think I am starting to ask questions which can be found by a simple google, apologies.

I am going to look into transferring my site hak8or.com to Ruby. Always eager to try out new things!

7

u/tofueggplant Feb 24 '13

Ruby's kind of like Python, but with different syntax and a few different features. If you know Python you'll probably find Ruby pretty familiar.

2

u/jyper Feb 24 '13

any language can theoretically compile to x86, I don't think any ruby does directly although you can use jruby to compile to java bytecode which can be compiled to x86 or other machine code by the java vm you are using.

That said it's easier to make desktop gui/cmdline aplications in ruby then in php. Ruby is a lot like python except that it's a bit more object oriented a bit more fast changing(for good and bad as library interfaces can be more unstable) and that since python is so similar and is already used in many categories where ruby could have been used(os scripting, app scripting, gui desktop applications, ect.) most of the time ruby is used to make website(usually using the rails framework).

→ More replies (4)
→ More replies (3)