It mapped from Ruby to C# really well. The only concept I had to add was a `BoardCell` base type for the `Mine` and `Empty` types so we could return either `Mine` or `Empty` in a typesafe way. Everything else matched conceptually 1-1.
It's 118 lines total, with 18 lines of whitespace, so 100 lines exactly. I figure the original Ruby code was also not counting whitespace so it's a fair comparison. I tried to not use any "code golf tricks" that would minimize line count. It's a full program; it could be copy/pasted into a modern .NET 8 project and run without any additional setup.
Note, I posted this same comment on the original blog post, but I've posted it here too as it might be interesting for HN folks.
https://github.com/JohnEarnest/Decker/blob/main/examples/lil...
I'm really not convinced that OOP simplifies or clarifies this type of program.
It's a really fun exercise, and a good way to practice new skills. Highly recommend it.
I eventually got it working with a combination of techniques from [this stackoverflow post](https://stackoverflow.com/questions/8730676/how-can-i-switch...) but it's not left my system in the cleanest of states.
Most Ruby devs I know are on Macs and none of them are running the ancient version Apple installs. Just like with most other languages, even JavaScript, you'll want to get a current or recent version.
Either use a version manager like RVM (popular) or ASDF (my favorite tool since it handles nearly all languages). You can also install Ruby with Homebrew, but I don't recommend using Homebrew for managing programming languages since you may want different versions on different projects.
radanskoric: You should reach out to the mods (contact link at the bottom of almost every page here) and ask to have your account un-banned.
And when I check his profile, almost every comment he's made is also marked as [dead] - but I don't see a good reason why?
Reminds me of my 2048 game clone in Ruby in about 100 lines (https://github.com/wkjagt/2048)
And I just saw that I did this - oh god - 9 years ago. Time goes way too fast.
https://stackblitz.com/edit/gridgame-minesweeper?file=index....
- "Oh, why are you doing procedural case statements? that's a SOLID anti-pattern, please refactor to polymorphism"
- "Oh, why is the Ascii Renderer class meddling in cell mine logic? `cell.neighbour_mines.zero? ? "_" : cell.neighbour_mines` should be its own method in a `Mine` class that is properly tested"
You're never allowed to just write code that solves a problem. It never ends. Your team has unlimited authority to slow you down with completely useless "feedback" that does not help anyone.
When I’ve found myself on teams like this, as a junior engineer I just did what was asked to get along and get experience. As a senior engineer, I often looked for a new job. As a staff engineer, I push back with as much politeness as I can.
Many engineers out there have traded getting it done for perfection. That’s not good judgement.
I'm beginning to think that the true reason for Ruby losing popularity is because some find it somewhat difficult to wrap their heads around it, but I don't know why -- some people maybe have a completely different mental model and processes in their heads? For me, from day one I got my hands on the language it seemed perfectly natural. Now I program in several languages with various features and properties (compiled/interpreted, strong/weak types, procedural vs OOP vs functional) -- all I can say is it is joy to write programs in Ruby. About the only things I dislike about it are the following: 1) they could've come up with better ways to signal code-block boundaries (keyword `end` is used with way too many different constructions) and, recently, 2) Type implementation where types are declared in separate files, which is probably sub-optimal. For (2), however, I do understand why it is the way it is: they needed something that would not break an already more or less complex argument definition rules (named arguments, default values for named arguments, etc.) and also something that was a layer on top of the language and not so much part of the language itself -- so maybe it's better this way?
Btw, anyone used types in Ruby? Any tips? I'm still avoiding this, wondering if it'd be a boilerplate and a constant annoyance and waste of time. But does anyone think there is a legitimate way to use it and benefit from it in Ruby (language being interpreted and not compiled)?
My take on typing and Ruby is that it makes sense in specific parts of the code where you expect to get high benefit from it.
Overall, I don't like using types for the whole project. The reason is that you end up losing some specific Ruby benefits, like being able to express the solution in a few very concise lines of dynamically typed code. Ruby is not designed to be a type friendly language and that shows when trying to use types. It works but it doesn't feel like pure Ruby anymore. It's definitely a compromise. You lose a bit of ruby expressiveness to get some type safety.
I want to emphasise that I am actually very fond of types. For example, I've been learning Rust and I really enjoy using Rust for very different reasons than I enjoy using Ruby.
I think that tools are best used in the way they were intended to be used. And for Ruby that's without types. For Rust it's definitely with types. I enjoy both very much.
In Ruby I'll use types in cases where I would actually prefer to implement the part in another language (like Rust) but using typed Ruby is going to be more maintainable than introducing a whole new language just for one section of the code.