Hyperloop – The Missing Ruby Front-end Library
ruby-hyperloop.io
ruby-hyperloop.io
This can be mitigated somewhat, see JSON Schema and others, but most of them are leaky abstractions. Being able to truly, completely re-use data structures, validation logic, and pure functions between use-cases has saved a massive amount of time and pain across a number of production projects I've worked on in the last two years; Javascript being the language in question.
I switch between ES6/7 and Ruby on a daily basis, and I don't feel that it holds me back or slow me down.
I actuallt enjoy working with ES6/7 now. It was painful to have to learn all the tooling involved but this library seems to be using the same tools. So it's unavoidable to learn the tooling anyway.
I hesitate to hold this example up as a shining beacon of the great power of using the same language on server and client. There were a fair number of pros and cons. But the end result was very useful and execution was relatively fast.
* Form validation/data sanitisation code
* Translation/internationalisation
* Data (de)serialisation
Also you can do fancy things like server-side rendering, although Google is capable of searching SPAs now. I don't know much about SEO.
The argument for less code sharing is that if you are working with a lot of teams and service-based architectures, there are some merits to duplicate your code and keep them redundant, to 1) enable hiring from more diverse backgrounds and 2) reduce communication/maintenance friction needed when you make changes to components would otherwise be shared.
We don't need to share everything
If the client is written in a different language than the server then you have to maintain two versions of the page code to achieve this, and they have to be in perfect sync. Hard to do. Easier to write the code once and transpile to JS for the browser (or write the back end in JS).
Plus you are a first class citizen in each world.
Thus:
* Ruby code = private methods that nobody else can see
* Javascript code = public methods that everybody can peek into
Once you solve the "how do I pass data from ruby to javascript and vice-versa" question, this mental model holds up quite well.
(My own solution to this question is this project: https://github.com/mariusandra/kea-on-rails , featuring server rendered react views (via react-on-rails) and seamless passing of data back and forth... but it might not be the best approach for your projects)
the leap to "okay, now that we're using the same language for both parts of our app, why not make a framework that lets you mix server and client side code in the same codebase" is more a taking that idea to its conclusion than the primary motivation for it.
As companies grow they simply start using the same languages over and over, without any concern if they are the best tool for the job.
With one language on client and server you get at least code reuse, if you modularize your stuff nicely.
In my experience it has everything to do with developers who like to feel under control and feel really uncomfortable if they are not the smartest person in the room.
Some of the other advantages: A common tool chain, including testing (we are using rspec), people don't align themselves as front-end vs. back-end developers, easier training for new hires.
Point taken about choosing the "right tool for the job", however there is nothing in JS that makes it a better tool than ruby. In fact I would argue (but it is opinion) that ruby is a far better tool than JS. So why not use ruby for full stack? If I felt that somehow JS was better than we would have worked towards using Node for a full stack solution.
Of course its not just the language, its language + available libraries and tool chain. In that regard Ruby is far superior.
The code inside the blocks are uncacheable; it's an expensive novelty. Plus these abstractions always break down. Our job is to build products that meet people's needs. Not to contort solutions into our preferred form, at the expense of the product.
Edit: spelling and minor changes
- micro-benchmarks are really good at telling you the story you want to hear.
- profiling erector revealed that it placed a lot of pressure on the garbage collector. This was back when it too was the "fastest templating library." Micro-benchmarks won't really tell that story.
Other issues:
- blocks are a good abstraction until they aren't. No doubt backtraces are better than with erector. This was seriously traumatic to debug, templates were a gigantic ball of mud.
- "_I_ don't need caching" isn't a counter-argument. The reality of using blocks to nest elements is that the boundary between "cacheable, static content" and "dynamic stuff" is indistinguishable.
It's not like caching is turned off in erector (or fortitude). People were constantly making changes to templates, shipping them, and having changes not show up because memcache isn't running in development.
You COULD try to argue that it's the same problem in erb or slim, except it mostly isn't. When ALL your code is ruby code, seeing the "cache below this line" is a lot harder.
The reason I use Fortitude (and love it) is that writing loops and conditionals and extracting methods or variables is trivially simple, you get great IDE support. It's just Ruby. And it is remarkable easy to write, factor, reuse chunks of code, import modules, etc. You can do all these amazing code-like things because it's code. Not some weird DSL that requires an extra parsing step (both mentally and on the comp) or you have to remember to add the equals sign so that it prints etc etc etc.
I think it is incredibly relevant that I haven't used cacheing much, I lose that with Fortitude but I don't care 98% of my day. Maybe y'all work on ridiculously performance intensive codebases, but there are so many other things slowing you down like the DB, or I/O, etc. I'd happily prefer to tune my db, prune some n-queries, etc than go trying to get silly Rails template-cacheing right. It is so error prone it's ridiculous.
Use Fortitude for the perks, not the missing feature that is incredibly painful to get right.
I'm pretty sure that the examples with Ruby code embedded in the HTML document are primarily intended as examples rather than as a template for production deployment. They seem to use Reactrb Express (http://ruby-hyperloop.io/gems/reactrb-express/) to perform the Ruby->JavaScript compilation in the browser. For production use this would be done as a build step to produce a compiled JavaScript file that you can include in Rails' asset pipeline (for example - see http://ruby-hyperloop.io/tutorials/showcase/#step-3-webpack-...).
I don't necessarily disagree with your other points, but I think this looks like it's reasonably well put together. If it works well the ability to reuse Rails models on the client might be handy for example.
> Not to contort solutions into our preferred form, at the expense of the product.
A lot of this depends on your starting point (what you already know) and what you have to deliver with the resources you have available. Sometimes building and using abstractions that increase a team's leverage is the right approach for the product, even if it's a limited tactical step rather than a strategic direction.
Though I remember thinking the same thing about Parse a few years ago, the BaaS product. Even going straight to SO was a search disaster.
That must be what you mean.
Second, React is maintained by Facebook. This project is not. If you're greenfielding an app and you base it on this framework rather than real React, then you better hope the app goes EOL before the framework maintainer decides to move on, otherwise you're SOL.
> Reactive Record compiles your Active Record models so they are accessible to the front-end and implements an API based on your models and their associations. Lazy loads just the data that is needed to render a component and is fully integrated with Reactrb and paired with Synchromesh to push database changes to all connected clients. ReactiveRecord and Synchromesh give you Relay + GraphQL like functionality with a fraction of the effort and complexity (the original idea for Reactive Record is credited to Volt and not Relay).
They're planning to support Synchromesh pushing updates to clients over ActionCable channels when the whole stack supports Rails 5. [3]
[1] http://ruby-hyperloop.io/tutorials/showcase/#using-reactrb-r...
[2] http://ruby-hyperloop.io/tutorials/showcase/#synchromesh