📜 ⬆️ ⬇️

Ruby Ecosystem (on Rails) with a bitter aftertaste, or “How we love to poke PHP”

This is a translation of the article Ruby (on Rails) ecosystem bittersweet or "we like to hate PHP" , written on May 30, 2016, i.e. recently. I completely agree with its author, and I myself have long been eager to write something like this lately, but I don’t have so much experience with Ruby, so my writings would not be as objective as the writings of a person who has this experience, and has it in good quantity. And here on you: everything is already collected in one place, and the thoughts are straightforward one to one as mine. Sin does not translate into Russian. Also, the article is generally very good as a small set of objective and impartial analysis of the two languages ​​of modern web development. In general, then - the translation of the words of the author.


many letters; do not read;
In this article, I talk about some facts and personal experiences to prove that PHP is currently livelier, more competitive, and also has a less connected ecosystem than Ruby. I'm talking about Performance, Syntax and Aspects of Coding, Community and Developer Tools.

If you have a desire to skip water - skip to the title "The main part begins here ..." :) But I need to say it ...


What? Another anti-ror sermon?


Well, yes, I started collecting material for this post more than six months ago, and I know about all the discussions that have been conducted on the subject of “for” and “against” RoR in recent weeks. The main articles discussed today are My time with Rails is over and Rails won: Elephant in the Room . I’m definitely not as experienced at RoR to say anything new about architecture that someone else hasn’t yet said. I just want to argue for Rails leadership in web development.


[PHP] ... fragmented, independent and isolated communities ... This is one big ocean of scattered islands.

AkitaOnRails said somehow , and this is all true on the one hand, and a lie on the other. Dear rubists, let me show you your closest competitor: PHP. And there is nothing special in Ruby for a typical Basecamp application that we cannot find in PHP.


The evolution of my vision ...


I came into the world of Ruby only about a year and a half ago, after more than five years of development in PHP. I experienced a lot of torment. This is not an easy migration and adaptation. Life was such that I decided to create from scratch a Ruby development team (on Rails) in MobiDev. From that moment on, I was involved in learning and accelerating the development of my Ruby juniors and middles.


Very soon, I realized one thing: all these hipster and cool-kids images from the world of RoR were a bit exaggerated. Today, RoR does not offer anything particularly better than any average PHP framework, with the possible exception of background tasks out of the box.


What is even worse: it stimulates some development approaches that are "considered harmful" © even in PHP. Here, the violation of the principle of a single duty and CQRS directly by the framework itself is encouraged. And, frankly, a large RoR application is all-magic due to the ubiquitous seals-patches of implicit inclusion in everything.


Just think of one example of a violation of the principle of the only duty ...


image


"Didn't we stop working with PHP for this reason?"


Sorry Nick , I quote your book, and do not agree with this statement. I see a huge amount of Ruby developers love to download PHP. Most of them have not seen a single line of real PHP code, but "my friend told me ... that this is a nightmare." Or they saw WordPress - the most popular and the most ugly in terms of PHP architecture code that has ever been written.


I want to say that this is not the correct way of thinking for 2016, and the PHP community has many things that are not in the Ruby community at the moment.


Piotr Solnica
The next generation framework will never appear in the Ruby world ... http://disq.us/9qybwk

And, sorry, but before going directly to PHP, I have to leave here two rhetorical paragraphs for Ruby ...


It is like domestic violence.


When I think of Rails and the reaction of most rubists to the suggestion of “thinking outside RoR”, it reminds me of the stream of consciousness of a victim of domestic violence. And something like Stockholm Syndrome dependent on RoR.


Imagine this sad but true story. Cinderella lives in a cold, scary and hellishly complex world. She fell in love with the charming prince. He is simply amazing: he understands her from the first words, makes her life so bright, promises to always love her and do everything for her that she asks ...


They got married and moved to his castle. And her life has changed a bit ...


After many years lived together, she could not take a step without His permission, He could even beat her when she tried. She has to report about her every step and adjust everything under His flow of life. She had long since forgotten how to live without his excessive care and help from the servants. All the people she knows and with whom she communicates are the same wives of domestic tyrants. And more and more often she heard from her “charm”: “Don't even think about leaving me! Nobody needs you, except me! You can't do anything alone!” ...


Vicious circle of demand


Answer: nothing. There is nothing programmed in Ruby to stop you from using your sharp knives to break relationships with your mind. We implement such good agreements through nudging and learning. Not through the prohibition of sharp knives and not through appeals to use spoons for slicing tomatoes.
DHH, "Provide sharp knives"

Education. Rails really teach us?


Developers are starting to use Rails. They learn only the rails. Can't take a step without them. They cannot distinguish between what is pure Ruby and what is a rail monkey patch. They do not see something better than this, and they do not want anything better. They can't even make a tiny SQL query without ActiveRecord. Performance? Who cares about this? Clients get on Rails marketing and the "wide community of developers." They require projects to be written on Rails. Developers use Rails because it’s so easy (not easy!), And Clients want Rails (demand creates supply).


When you think about where to go after Rails, you’ll understand that there’s really no place to go. Clients are reluctant to write non-Rails applications because they "most likely would not have found non-Rails developers." The same is with the developers: they are afraid to leave Rails, because "they will not be able to find non-Rails work". Vicious circle. And there is no longer any difference, "supply creates demand," or vice versa.


Such a problem does not exist in the PHP world. Clients almost never require any particular framework. Developers, in turn, have the opportunity to freely choose the tool that they know and which best suits the requirements. Yes, there are a lot of Rails-like frameworks, but also there is a set of frameworks with an excellent philosophy.


╰ (• ̀ε • ́╰) The main part begins here ...


Evolution and Performance


In 2005, PHP released version 5.0, and OOP approaches became possible to implement (since the release of version 3.0, there were very limited OOP capabilities). Of course, RoR here is the assignee. And PHP could not show something competitive for a long time.


But, starting in 2012, PHP received a massive push forward with version 5.4, HipHop VM from Facebook and the expansion of the ecosystem. Today, with version 7.0 and Facebook HackLang , PHP has twice the performance and low memory consumption. This is definitely no slower than Ruby 2.x.


The biggest advantage of PHP applications is that the speed of the code does not depend on the Dev / Production environment. It does not require reloading classes (since each new request uses the actual code). Only debugging extension gives some penalty. But the Production environment does not throw you some unexpected behavior, as there is usually no difference where your code runs.


The future of PHP is clear because it has the corporations behind it - Zend, Facebook, and so on. They are constantly working on the language in order to make it even better and faster.


What about ruby? Many foggy realizations with foggy perspectives. (comment of the translator - there is still such a thing as Elixir , which is also largely a Ruby receiver)


Community


Despite the fact that corporations are investing in the development of PHP, in itself it has a real community - PHP FIG (Framework Interop Group)


The group’s idea is to communicate with project representatives to discuss common problems between different projects and jointly search for solutions. Our primary audience is ourselves, but we understand very well that the rest of the PHP community is watching us. If others want to accept what we do, they can do it, but that is not the goal. No one in the group wants to tell you, as a programmer, how you should develop your application.


And these guys from a bunch of PHP projects work together (yes, sometimes they quarrel very loudly) and offer well-designed PHP Recommendation Standards. And the community really takes them after some time.


Thanks to PHP FIG for the fact that we now have such important things as Coding Standards and Startup Standard for Namespace. It's hard to overestimate how important these things are to modern PHP. It really gives us the opportunity to combine different projects and libraries in one non-conflict code base.


I honestly do not see anything like this in Ruby, there is only the Rails dictatorship.


Packages


Yes, Bundler and Gems were amazing for Ruby, and manual copy-paste in PHP was terrible. Since 2012, PHP has received Composer, thanks to the PHP FIG standards. Its purpose is to manage package dependencies and autoload application code.


The biggest difference is that PHP dependencies are stored at the project level (each project downloads its own set of dependencies), and for this reason there can be no conflicts between projects.


The code is automatically loaded on the basis of Namespace. And in practice, this works better than Constant Autoload in Rails with Ruby modules. In PHP, all packages have a unique vendor name in Neimespace, and this makes it very easy to track which code was loaded. I really have a lot of problems with this in Rails, and have no problems on the PHP side.


PHP has the Outstanding Packs League - a group of developers who have teamed up to build strong, well-proven PHP packages using modern programming standards. They have many high-quality independent packages for Routing, Dependency Injection, Events, Teams, Authorization, Time Manipulation and more. And there is not one restriction for you to use these excellent libraries in any PHP framework. You can even combine them and create your own framework!


Another great example - Aura for PHP is a full-featured framework, but consisting of loosely coupled components that you can use on your own, or combine them with what you need.


[PHP] ... fragmented, independent and isolated communities ... This is one big ocean of scattered islands.

Hmm ... Being reusable, isolated and loosely connected is not about being "fragmented" or "fragmented", and the Magic Monolith is not the only architectural option!


Monkey patching


Should I tell about the fact that PHP does not have the possibility of a monkey patching at its core? And that the packages do not collide with each other when some kind of seam-patch has already created a similar method in the object. Yes, this is a limitation of PHP, you can't do a lot of magic like in Ruby, but I really do have a better life without these sharp knives, and it's better to think about the right OOP design than patches.


The big advantage is that the utilities are provided explicitly. Yes, there are some of them, and most frameworks support their own. But any framework pushes something into your application.


! 5.minutes.ago — !

. realntl Reddit ( )


: . , - , Integer#minutes ActiveSupport, :

class Foo
  MINUTES = 5

def bar
    MINUTES.minutes.ago
  end
end

, . , Integer#minutes , — , . Integer#minutes (, , /) , , — , "". , . , timecop style gem . , , . : , .

5.minutes.ago Ruby? Time TimeMath.minutes.decrease(Time.now, 5).


Rails - , " ". Rails Array#second_to_last, Array#third_to_last ArrayInquirer. , .


()


Ruby "" . PHP . $this, :) , , , . IDE .


Ruby admin?/access?, PHP ? , PHP isAdmin/hasAccess.


PHP (!) . — , , . , . , IDE.


DSL


PHP DSL, , Ruby.


DSL , - Vagrantfile. , , DSL . , DSL. , DSL, . " , ".



Ruby . (, ). , ! :D " *** ". " ", .


PHP . , — " " __get __call . . , , , , .



, . PHP . , PHP FIG . . . .


:



Rails - PHP (, , Rails :)). Yii . , , . .


PHP "" ! . ( ) , " ".


, -, " " (Lumen < Laravel, Silex < Symfony). -, .



Ruby? : Rails. Sinatra, -.


Hanami.



, PHP ( Trailblazer Ruby). . , Laravel DI, RequestForms, Events Command/Handler, Entity/Repository, .


PHP , , , Rails — . .


UPD


PHP: Broadway


Broadway CQRS - . Broadway - , . , , CQRS \ ES.


ORM / DAO / Data Access


ActiveRecord ORM', Entity/Repository. Yii ActiveRecord DAO (, , , NoSQL), Doctrine, Eloquent, PropelORM, .


Rails ActiveRecord — . Hanami DataMapper-. Sequel.


, DataMapper Ruby NoORM- ORM- .



Rails Sprockets, : JS, CSS, SASS, LESS, . .


PHP . PHP . Rails .


JS/CSS . , Sprockets ( Dev , assests:precompiletask , JS -). JS/CSS Node.js Webpack/Babel. . Rails .


Node.js + WebPack ES6 + SASS + JS + , , . PHP, Rails. Rails , .



, PHP — . , . PHP , PHP — , + (Redis, Beanstalkd, ).


Ruby DelayedJob, Sidekiq, . , "", — . Ruby Redis - .


IDE -


, Ruby IDE, Sublime, .. , IDE RubyMine Ruby. - . .


PHP, , , . PHPDoc, , 100% . , PHP: . Ruby.



Ruby . . RSpec, Minitest Cucumber : , BDD.


PHP — PHPUnit. . Codeception BDD- . , Cucumber ( Behat), , PHP. , .


, TDD , .



.


, Ruby PHP!


, - , Ruby on Rails -. " PHP " , , Ruby. — , !


2016.06.01


Reddit, .


Ruby On Rails,

Rails . . , Ruby. PHP .


, - ( ).


5.minutes.ago

, :) . " ", " ". 5.minutes.ago — .


Laravel

, RoR Laravel, Laravel — RoR PHP

RoR Laravel , ?

, Laravel Rails , Taylor Otwell. , — , Laravel PHP, , Laravel ( PHP, , ). Rails — Ruby.


Laravel DDD, , , , , Rails, : , , , .


Behat / Cucumber

, " ". Behat

:) , .

, Behat / Cucumber. , , . Behat . , ( , PHP Ruby). , , ( ), .. PHUnit + Codeception PHP Minitest+Capybara Ruby.


')

Source: https://habr.com/ru/post/306564/


All Articles