A decent VS Code and Ruby on Rails setup
railsnotes.xyz
railsnotes.xyz
I really don’t get the VS Code love.
It’s fine as a free editor.
But laggy and cluttered. It’s like the Las Vegas of editors.
I always feel compelled to come and hang out on these threads as I really don’t understand the VS Code love, but I try to as surely I’m missing something…..
I think the UI is way cleaner than e.g. the old JetBrains UI. The new JB UI is on the other hand pretty comparable to VSC.
One or the things we really like about VSC is how “easy” you can “enforce” opinionated coding styles and tool setups through sharing the .vscode configurations directly in your repositories. We’re not too fascist about it. The opinions are semi-democratically decided and you’re free to override them to some degree. But because our deployment pipelines are in fact fascists, it’s very helpful to have those “global” settings at times. Like when we’re onboarding new developers, or when we’re using external consultants. Because it lets anyone just jump in and build code the way everyone else does.
Now, from the sound of things getting your VSC groove on with Ruby isn’t as easy as it is with something like Typescript. Which leads me back to the thing about tooling. Because VSC is certainly better for some things. Even something like C# which is getting good in VSC, is still “better” in VS. You’re probably very likely to use VSC for C# as VS sort of sucks, in our team only one person is still clinging on to VS as an example, but it all comes down to support.
Now, my VSC isn’t slow or laggy, but it can be. I have a couple of extensions that are just horrible for performance, but I tend to turn them off any time I’m not using them to avoid this. Similarly you’re going to need to know your way around the settings to get it to really fit your needs and you’re probably not going to have a good time if you sort of “google” configure your VSC because many of the guides are absolute trash. As it is with many things, it’s very hard to tell the trash from the gold, so the only way will often involve reading the manual. You can get away with not doing that for most usage with common languages, but for power use you’re eventually likely to have to dig into Microsoft’s horrible documentation.
The real selling point is the plugins, notably the Remote Development extension. This lets you locally run the IDE while the code runs/lives on a remote (SSH/Docker) host which could be beefier or specific hardware. Complete game changer that I now find impossible to do without.
If you want, I could give a list of inexcusable grievances that are maintained to this day. My favorite would be this: https://github.com/microsoft/vscode/issues/40233 . From the outside, would only take a handful of lines to read two configuration files instead of one. Open for six years.
It allows me to leave my MacStudio at the office and work from a lower powered laptop at home (using Tailscale to connect) and everything feels like it’s running locally (it seems to run a service on the remote machine that indexes your files so the fuzzy file opener and full project search feel as fast as if they were running locally).
I have tried CodeServer on the remote machine (VSCode open-source in a browser) but that seems to get random pauses (presumably GC or something like that).
If anyone knows of something similar available outside of VSCode I’d love to hear about it.
If you predominantly work in TypeScript, for the web, there's no better editor.
It's faster & "lighter" than any JetBrains product, but has excellent "auto-complete" that's fairly intelligent / context aware, while still being almost as fast / lightweight as Sublime. Use with ESLint + Prettier, with format on save enabled and you tend to fly through typing TypeScript.
It does pretty well for React Native too, it's reasonably good for JavaScript, and pretty poorly for anything else (Go, Ruby, PHP, Java / Kotlin, Swift / Objective-C), C/C++/C#.
VSC is not a speed demon but it's fast enough (I think there is a certain audience who loves to hate this; JetBrains products are measurably slow, but nobody ever complains about it). I have the suspicion that plugins may impact the experience.
The main layout is very simple (besides the status bar, but that takes very little) and almost anything can be bound to a key combination, so one can reach everything very efficiently (for example, even if the sidebar changes to something undesired, it's possible to switch to Explorer via key binding).
The major problems I've found with Ruby on VSC are:
1. VSC's built-in support for Ruby is just terrible - indentation is broken, and based on the bug tracker, they have no interesst in fixing it.
2. Solargraph is unusable for projects of even moderate complexity - it's extremely slow and inefficient, to the point of hanging in some cases.
I understand OPs points about ERB it seems to be a wasteland of development. I switched to liquid templates which took a decent bit of effort to implement, but well worth it for shopifys amazing liquid extension/support, which is quite configurable too for custom handlers.
Recent releases are technically faster than ERB, and I really appreciate the compact structure of the markup!
I'm really excited for where some of the extensions in the article are going - the RubyLSP has been improving slowly and steadily and I'm hoping that this is the year it gets _really good_. Other extensions like the StimulusLSP are niche, but awesome, and on the Twitter thread for this article (https://twitter.com/hrrsnbbnt/status/1759900961760477681) someone even pointed me to a new ERB formatter that looks promising.
TLDR; Rails is alive and well! Ruby has never been a first-class citizen of VS Code, but there's still some awesome extensions out there to give you a decent experience. And it's getting better!
You appear to be working on projects with Sorbet (which I tried to like but found it fell short in practice, notably outside of the app use case i.e it's mostly useless when authoring a gem) so it may be a tall order to try on those. Maybe you can give RBS+Steep a shot on some small project?
RBS: https://github.com/ruby/rbs
RBS collection (for those gems that don't ship RBS signatures in `sig`, integrates with bundler): https://github.com/ruby/gem_rbs_collection
Steep: https://github.com/soutaro/steep
VS Code: https://github.com/soutaro/steep-vscode
Sublime Text: https://github.com/sublimelsp/LSP
Vim (I'm working on it): https://github.com/dense-analysis/ale/pull/4671
In the Python libraries I maintain, types are useful to anyone who installs the default Python VS Code plugin, because it gives them intellisense (but doesn't give them red squiggly lines for type errors) even if they do nothing to set up types or a typechecker.
Is that or will that be the case for Ruby/Steep?
We plan to do that at some point for the Ruby Datadog tracer public API, so that users can have intellisense and don't need to jump to the docs.
The process is basically `rbs prototype` or `typeprof` to generate a sig file and steep then uses that. TBH it's not that much of a chore as it sounds and already gives you good-ish results. That gives you a bunch of material to work from and progressively refine types.
Speed is very good, I didn't notice anything slow.
The combination of verbose type definitions and limited support for the kind of types rails often uses made it a poor ROI for us, but it did find some bugs.
Personally don't like it, but I also don't like mypy. I do like TypeScript though, mostly.
When you're hacking together an MVP as quickly as possible, it may seem like a brilliant idea to not have types. Then you have a real company and a larger team and you find out that not having types causes lots of problems. Then you graft an ugly hack like Sorbet onto your code base. It's more work and more error-prone than having a real language with types.
The official Ruby motto should be "penny-wise, pound foolish". Everything about the language is a disadvantage when you have a large code base.
Yeah, it's hard to find a decent team, so we work with less experienced guys who need a lot of safeguards like static types ;)
Ruby solves this problem: you do not need big teams, so you are more comfortable finding better developers. Ruby allows to reduce team 5x.
Getting it to play nicely with Rails and other gems that did metaprogramming magic was a constant pain in the butt though.
I would say it was immensely worth it. It caught bugs for me before runtime on a daily basis, and enabled refactors that would have been so much more difficult without it.
It was far from painless, and there were plenty of outstanding issues even when I left. But I consider it an invaluable and essential tool for any large ruby codebase.
I was particularly impressed at how fast sorbet was. Way faster than typescript on a comparably sized codebase.
Or Ruby Mine.
Anything but VSCode for me!
However, I personally prefer RubyMine since it comes with everything out of the box.
I only use VS Code as a text editor replacement.
A lot of people set debugger breakpoints by inserting "debugger" or "binding.pry" manually. That also sucks because you can't easily disable a breakpoint after you've reached it. And of course it's an idiotic way of inserting breakpoints, because you can't just detach the debugger - you have to delete every breakpoint if you want the the server to just run.
The language itself is also badly designed. A single-line block uses { }, but when it's multiple lines, it has to be changed to "do" and "end" - why? Do/end is dumb for the other constructs - VSCode can easily jump to a matching paren/bracket/brace, but not to the matching do/end. Who thought |x| was a good idea? Look at C# to see how this should be done. That's just scratching the surface, there are so many shitty features in this language.
Then on top of this, you have Sorbet - grafting type checking onto the code, but outside the language. It's about 100 times uglier than just having typing built into the language. Today I learned that you can't provide a Sorbet sig for a module_function - Rubocop doesn't understand it. Rubocop runs as part of "git commit", so you can't do anything that Rubocop doesn't like.
All of this is so shitty and amateur and primitive and backwards. Right now is not a good time for finding a new job as a software engineer, otherwise I'd be out of here looking for a job where I can use a real language with real tools that work and improve productivity rather than killing productivity like the Ruby circus.
Rails has some nice features, but for every bit of productivity gain that it gives you, there's about 10x as much negative impact on productivity.
It doesn't have to be changed. {} work fine on multi-line blocks also. It's probably your linter that's forcing you to change them to do... end blocks: https://try.ruby-lang.org/playground/#code=3.times+%7B%0A++p...
Some developers will claim "it's a preference" or mistakenly assume it can be compared side by side with other back-end stack. This just stems from critical gap in required software engineering knowledge - Ruby does not and cannot compete with other stacks. I tend to be critical of Go, but I would pick it every time over Ruby if the circumstances would not let me use something better.
(seriously, friends don't let friends deploy new projects in Ruby, use C# or Kotlin or any other compiled language that strikes your fancy)
I just randomly started learning Ruby for shits and giggles over this last week, so I'd love to hear more of why not to go down this path (not that I necessarily would hit the brakes)
I've also been dabbling in Go over the last year or so and really enjoyed playing around with it, but I do find it a bit verbose. On the other hand, its performance is really impressive.
It's brilliant for side-projects and smaller teams; At 50+ devs working in the same Rails codebase, it can start to get pretty chaotic which is potentially where a lot of the HN-negativity comes from.
Over time I learned that Ruby and Rails are as told easy to learn, but sadly you'll need some time to master the Language/Framework. And the difference is quite big and easy to overlook once you do.
- it makes a lot of unconventional/strange design decisions
- the nature of the language makes it difficult for IDEs to offer good support (e.g. autocomplete, show what methods you can call on a given object)
- it encourages people to write unreadable code to show how clever they are
All of these things are the opposite of fun and efficient and easy-to-learn.
It is also not early 00s anymore, when you pick an interpreted language, you are not getting "better productivity and tooling". In fact, most interpreted languages lag behind other major languages significantly in the form of JS/TS, Python and Ruby suffering from different woes when it comes to package management, publishing, static analysis on big problems and overall trying to graft type system on something that wasn't designed with one in mind. I would say only TS manages to stand apart with being tolerable, and Python sometimes too by a virtue of its popularity and the amount of information out there whenever you need to troubleshoot.
If you liked Go but felt it being a too verbose to your liking, give .NET a try. I am advocating for it here on HN mostly for fun but it is, in fact, highly underappreciated, considered unsexy and boring while it's anything but after a complete change of trajectory in the last 3-5 years. It is actually the* stack people secretly want but simply don't know about because it is bundled together with Java in the public perception.
*productive CLI tooling, high performance, much more expressive and FP-style than Go, works well in a really wide range of workloads from low to high level, by far the best ORM across all languages and back-end framework that is easier to work with than Node.JS while consuming 0.1x resources
- it allows people to write difficult-to-read code. Everyone invents their own DSL for showing how clever they are
- the lack of typing built into the language means that either people and IDEs have no idea what type anything is, and you run into runtime type errors that should have been caught at compile time, or you use Sorbet to add types, and it looks like crap and reduces readability
- the tools (VSCode, RubyMine, etc) can only partially understand the code, so they can't help you much, and you're back to the 1980s in terms of tool suport while writing code.
Ruby is really not easy to get into with its n ways of doing things and supposed "magic" methods. I think it can be worth it. Rails (7) feels very productive right now.
(Never had to deal with sorbet/rubocop though and guilty of just writing "debugger", Rubymine has normal breakpoints as well though.)