When comparing PHP vs Ruby, the Slant community recommends Ruby for most people. In the question“What is the best programming language to learn first?” Ruby is ranked 17th while PHP is ranked 29th. The most important reason people chose Ruby is:
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters. presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"] for ss in 0...presidents.length print ss, ": ", presidents[presidents.length - ss - 1], "\n"; end
Ranked in these QuestionsQuestion Ranking
Pro One of the most common languages
According to the 2015 Stack Overflow Developer Survey (26,086 people surveyed), PHP was the 5th most popular/used language at 29.7%.
Pro Lots of tutorials online
Pro Used by most common CMS platforms
Many clients are looking for an easy-to-update web site that's flexible and free. Drupal and Wordpress fill those needs very well.
Pro Most prominent language for web applications
Part of the de facto standard web application stack.
Pro Great third-party package manager
PHP standard library is somewhat subpar, but if you need plugins, language features, composer has them all( you can even puzzle together a custom framework from composer).
Since 7.x was released, PHP has become a pretty fast language.
Pro Lots of PHP frameworks available which help with development
PHP people love frameworks, and with frameworks such as Laravel, you can build a web app or API really fast (Facades, ORMs, scaffolding etc.)
Pro Great documentation
Pro Clean syntax
Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java. For beginning programmers, this means the focus is on the meaning of the program, where it should be, rather than trying to figure out the meaning of obscure characters.
presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"] for ss in 0...presidents.length print ss, ": ", presidents[presidents.length - ss - 1], "\n"; end
Pro A large ecosystem of tools & libraries
Ruby has a large ecosystem of tools and libraries for just about every use. Such as ORMs (Active Record, DatabMapper), Web Application Frameworks(Rails, Sinatra, Volt), Virtualization Orchestration(docker-api, drelict), CLI tools(Thor, Commando), GUI Frameworks(Shoes, FXRuby) and the list goes on. If you can think of it, there is probably a gem for that ( and if not you can create your own and share with the community).
Pro Widely used
Ruby is one of the most popular languages for developing web sites. As a result, there's an abundant amount of documentation, sample code, and libraries available for learning the language and getting your project up and running. The most popular features are just 'gem install' away. Additionally, it is easier to find Ruby jobs because of this.
Pro Ruby on Rails
Lays out an easy to follow and opinionated MVC pattern that teaches best practices through necessity.
Pro Newbie-friendly community
Pro Test Driven Development, #1
It's the fore-runner and trend setter for TDD.
Pro Hugely object oriented
Object oriented programming is one of the most important concepts in programming.
Meta-programming provides efficiency and freedom.
Pro No indentation
No indentation increase development efficiency.
Con Poorly designed language
Despite its widespread use, PHP is generally looked upon poorly from a design point of view. The consistency of function names and function argument order, lazily and borderline non-functional implementation of object oriented programming, can only receive requests via POST methods, slow version adoption (the PHP you learn right now may not work on every webserver you'll work on), and a focus on "hacking things together" rather than "doing it right". These are all very common complaints when it comes to working with PHP. While not a bad language to learn, PHP is not at all a good language to learn first, as it will probably teach bad habits.
Con Immense catalog of insecure frameworks
The most serious security problems in websites on the web today are almost universally found in popular PHP frameworks, CMS platforms, libraries and code samples, almost all stemming from poor language design, bad tutorials and awful resources.
Con After python, probably one of the worst languages ever
Con Poorly designed language, awful syntax & luckily on the decline
Nobody in their right mind is using PHP for new software, if you decide to learn it as your first language you'll be stuck working in teams with old developers who have had no interest in the computer programming field since they landed their first job while maintaining some 2000 era archaic website codebase.
Con Most tutorials are out of date
A lot of very bad tutorials are still widely circulated among beginners, and these tutorials teach very poor programming practices.
Con Most resources are poorly-written
Few resources exemplify the "correct" or secure use of features.
Con Interpreter being too permissive
If you forget the dollar sign, the variable name will be converted to a string.
Requiring a library can change the rules of the language. This is very confusing for beginners.
Con Its ecosystem is limited outside of web development
If you're looking to host, generate, manipulate or secure a website, Ruby is your language. There's also some great support here for infrastructure as code work via Chef. However, it just doesn't have the depth and breadth that Python does. Things like native UI development, high performance math, and embedded / small footprint environments are barely supported at all in Ruby-space.
Con Arcane grammar based on Perl
Ruby is too complicated for beginners:
- arcane Perlisms;
- semi-significant whitespace;
- parentheses are not necessary around method arguments, except for sometimes they are;
- control constructs could be elegantly implemented with block like Smalltalk (Instead they're baked into the grammar.);
- verbose block syntax, unless it happens to be the last argument. (proc lambda).
- There are too many exceptional cases and arcane precedence rules.
Con Meta-programming causes confusion for new developers
The ability for libraries to open classes and augment them leads to confusion for new developers since it is not clear who injected the functionality into some standard class.
In other words, if two modules decide to modify the same function on the same class can introduce a number of issues. Mainly, the order in which the modules are included matters. Since you more or less can't tell what kind of "helper" functions a module might write into any class, or for that matter, where the helper function was included from, you may sometimes wonder why class X can do Y sometimes but not at other times.
Con No docstrings
It's hard to access Ruby's documentation from the REPL (irb), unlike Python, Lisp, and Smalltalk which let you ask functions how to use them, which is a great benefit to the beginner, and which also encourages you to document your program as you code it.
Con More than one way to do it
A problem inspired by Perl. The core API interfaces are bloated. There's at least four different ways to define methods. More is not always better. Sometimes it's just more.
Con Does not teach you about data types
Since Ruby is a dynamically typed language, you don't have to learn about data types if you start using Ruby as your first language. Data types being one of the most important concepts in programming. This also will cause trouble in the long run when you will have to (inevitably) learn and work with a statically typed language because you will be forced to learn the type system from scratch.
Con Dynamic type system
Majority of bugs could be resolved with types.
Con Viewed as a web development language
Despite its flexibility and performance, Ruby is often seen as being unsuitable for other tasks by those who are not familiar with it. As such, a lot of discussion about it centers around Rails, which is not at all relevant if you're using Ruby for something else, such as game development.
Con Focus on Object-Oriented Programming (OOP)
Focussing on OOP in a beginner stage is an easy and popular plan, but not the best one.