Better HN
topnewbestaskshowjobs
Log inSign up

hakunin

2,515 karma · joined Mar 4, 2010 (16y ago) · 549 submissions

https://max.engineer, mastodon:ruby.social/@maxim, x.com/hakunin, bsky.app/profile/max.engineer

meet.hn/city/43.1009031,-75.2326641/City-of-Utica

---

Submissions

comment 3y ago · link · parent

Frankly, parentheses was the last thing on my mind. I typically use them by default, and remove them in cases where it might make sense.

Mostly I was thinking about stuff like arrangements of hashes, arrays, method arguments, naming of methods and variables, various styles of method chaining, block usage, etc.

comment 3y ago · link · parent

I think in general it's almost impossible to cut out human consideration and still get auto-clarity. With an auto-formatter you gain a little speed and lose a little readability. I think most people are really arguing about whether this trade off is worth it. Some are arguing that any readability gains are minimal (and debatable), but then it's like arguing that there's no point to being a better writer, and information can just be auto-formatted for human consumption with a set of standard heuristics. I guess we might actually get this world once everything is written by ChatGPT to maximize consistency. But then, how can we both claim to like complete and total mechanical consistency in code, and dislike it in any other form of writing? If code can be written more than one way, shouldn't we optimize it the same way for fellow devs as good writers would for their readers?

comment 3y ago · link · parent

You’re right that if your goal is to write English-like code, then clarity may suffer. The same is true if your goal is to write consistent strict mechanical code. The only goal I think that makes sense, is to go for clear code based on shared context with your team. That said, I don’t see how the rails doctrine inhibits one’s ability to write clear code.

comment 3y ago · link · parent

Problems like these often come from the pressure to ship fast, and not writing code 2-3 times to find a good way to express something. If you're going to rush through abstracting things away, I'd rather you duplicated. If you will take time to express it well, then I'd prefer a good abstraction.

comment 3y ago · link · parent

While those decisions are completely meaningless as far as performance or correctness of your program goes, they do have value for readability. One way to deal with them is of course to install something like standardrb and never think about it. The other way is to read the code you just wrote, and see what reads clearer/better in a specific case.

comment 3y ago · link · parent

While this talks mostly about data warehousing, oftentimes denormalization is useful for everyday web app data storage. If your web app (usually on Postgres) is mostly frequent reads and rare writes (most web apps are) — there's no excuse for your pages to load slower than a static site. Store your data as normalized as you want, add a denormalized materialized view, update it on writes, render pages based on the view.

Of course I'm talking about 95% of the apps where this is acceptable, not 5% where table locking can cause problems, leading to the need for concurrent update handling.

comment 3y ago · link · parent

We had a use case at one of former jobs where we had to lookup entries in hundreds of megs of static key/value data (vendored with the app), but it didn't have to be super fast and we didn't want to waste any RAM on it. Since everything is on SSDs, I wrote a lib[0] that was just seeking sorted data in files with pread and binary search. Worked perfectly for our needs.

[0]: https://github.com/maxim/wordmap

comment 3y ago · link · parent

One advantage of the "Another Solution" brought up in the article is that the code you write to create JSON for your web pages can be in large part reused for your mobile API. Certainly mobile screens are shaped differently, but not entirely. The trick is to abstract JSON-rendering logic in a way that lets you reshuffle bits and pieces for your mobile.

Disclaimer: I wrote the linked article for that solution.

comment 3y ago · link · parent

The first hard problem is to understand what to build. The second hard problem is to build it in a way that is clear and maintainable.

I wouldn't discount the importance of clarity in the way you code. You might end up writing the right solution, but because you didn't communicate "what", "how", and "why" clearly enough in your codebase, you will setup other developers (and potentially the business) for failure.

comment 3y ago · link · parent

So far each new Apple financial product makes me research and re-evaluate my options. When they announced their credit card, I got into "cash back" (thankful that I did), and ended up always getting good percentages back on every purchase. Apple Card was a jumping off point for further research. (For those curious, I ended up with Bank of America Premium Rewards at Platinum Honors tier + Amazon 5% card, Target 5% card, Lowe's 5% card, Apple 3% card, etc).

Now that they're announcing Savings, I'm thinking to re-evaluate my Ally savings account. Apple's is better, but I'm already seeing mentions of Betterment, Robinhood, and Wealthfront here. What I'm looking for is a no-fee, high yield, good FDIC insurance. I'm also looking to start a long-term investment account for my young kid, and it would probably be convenient if I could do them both with the same bank.

Any recommendations?

comment 3y ago · link · parent

You know how it’s always easy to educate your colleagues when they make a sub-optimal architectural decisions that could bite them in the long run? How readily they accept your insight and proceed to rethink their mental models? No? Not even experienced engineers?

Now imagine an average patient, like a mom with 7 kids that doesn’t speak English, or a 16 year old dad who smells intensely of pot. Vast majority of the patients are very different than our engineering bubbles, and doctors are humans who are trying their best.

For people who are willing to have a deeper conversation, some doctors will engage more meaningfully. But most of the process for doctors is to give you instructions to follow, then when you report back, alter them, or proceed as before.

Most people try the first thing doctor asked, and if it didn’t immediately work, change it themselves, and/or go to a new doctor. Then complain how they’ve been to 12 doctors and nobody helped, but then they stumbled on some YouTube guy who said to take 5000mg of vitamin C every 2 hours, and their back pain went away (hint: it went away on its own).

comment 3y ago · link · parent

> It's not anti-science to take your health into your own hands.

It depends on how exactly it was taken into one’s hands right? Can’t really know if it’s pro-science or anti-science until you see what a person is doing. Most people do pretty irrational stuff, based on stories of a doctor in my family.

comment 3y ago · link · parent

I assume you're explaining the fear, because the opposite is true. You'd be lifting a barrier. The barrier is you doing all the legwork while having all the institutional knowledge. Business cannot afford you doing the legwork, you need to be mentoring and delegating.

comment 3y ago · link · parent

One mismatch I often see between engineers and management. Engineers: "I must not be doing the best I can, because I'm not keeping up with work. Gotta work faster, gotta do better." Managers: "engineers are professionals with strong opinions who will always tell me when/if they need anything to help them get their work done. Right? If they aren't saying anything, it's their own fault, right? They're adults, right?"

Unfortunately many engineers (and humans generally) can't easily recognize and articulate what they need. One theory of mine is that we assign senior-sounding roles in this industry too readily. "Senior engineer" sounds like they would know how to handle this, but while they might be great at programming, they often have little experience recognizing their own limitations, asking for help/resources, and understanding that this level of self-awareness and focus on outcomes would make them look better, not worse.

If I was to give one piece of advice to an engineer in a similar position: you will always look more mature and professional if you evaluate your situation and explain what sort of help you need, than if you silently keep burning yourself out while the quality keeps slipping.

If you're management and you actually reprimand them for asking for help, you will have trouble retaining engineers. It would be justifiable for them to look for work elsewhere on these grounds.

comment 3y ago · link · parent

I've had way more success than I probably should have using something I now call "empathy driven debugging". I almost never use a debugger, instead I try to imagine I'm the person who wrote this program, and imagine where I might introduce this issue, and almost every freaking time I find the craziest stuff very quickly.

comment 3y ago · link · parent

The key to its success I think is controls. I could never feel comfortable with portable gaming because controls always felt clunky for games I like. This thing treats controls as the centerpiece, allowing seamless sharing of layouts between players: just pick the most popular layout for any game. You can play freaking real time strategies on this thing fairly comfortably.

comment 3y ago · link · parent

I hate gym too (also mid 30s), and use the hate as a tool. I hate it so much, that nothing will stop me from going, because I'm always at the lowest possible desire level anyway. I don't care if the weather is bad, if my mood is bad, or anything else. I just deliver myself to the place no matter what. For over 13 years now.

(People who like gym risk not going when they don't like it. I have no such risk. I'm not tethered to liking.)

But here's the real trick: if you can afford it, get a personal trainer.

Pick a cadence (e.g. Mon/Wed/Fri or Tue/Thu/Sat), deliver yourself to the location no matter what, and let trainer take over from there.

comment 3y ago · link · parent

Here’s a list of practices I call mindful code reviews. You shouldn’t unnecessarily extend the loop, but you also shouldn’t rush or auto approve. https://max.engineer/mindful-code-reviews

comment 3y ago · link · parent

> he was nearly always saying things that I felt were a bit "off"

One of such things is "screaming architecture". It is a good idea in theory, but only if you already know what the architecture should be. Most new projects don't know what they need up front, and discovery happens over time. Screaming architecture is bad for this process. It inhibits it, requiring a ton of refactoring because of early assumptions. One thing that is known up front is entry points. (CLI, requests, tests, bg jobs). They're a lot more likely to stay around forever. Custom architecture should emerge underneath them. I guess we can call it whispering architecture.

comment 3y ago · link · parent

I couldn't fit this part in my tweet, but this is an important caveat.

comment 3y ago · link · parent

Seems like an appropriate time to share my 4 reasons to leave a code comment:

1. An odd business requirement (share the origin story)

2. It took research (summarize with links)

3. Multiple options were considered (justify decision)

4. Question in a code review (answer in a comment)

comment 3y ago · link · parent

If you're basing on a lang-specific container like ruby, then it's the version of that container in the FROM line. Notice how ruby images come in various versions of OS (https://hub.docker.com/_/ruby). You can specify that as part of the FROM string. However, they also let you drop the OS part, and only specify ruby version. This will usually default to an image with the latest OS provided by that docker repo. Nothing to bump in this case, just occasionally rebuild your own image from scratch, instead of from cache, to make sure it downloads the latest base image.

comment 3y ago · link · parent

Ah, I accidentally lied by trying to reconstruct a vague memory, apologies. Now I'm remembering it in more detail.

It wasn't lack of defaults, it was handling of defaults. Portrayal does a couple of smart things like evaluating defaults in a specific order in the correct context (while still only evaluating once), such that this becomes possible:

    keyword :name
    keyword :greeting, default: proc { "Hello, #{name}" }
I like being able to do this. (This also works gracefully with subclassing.)

The coercion argument is good, but I'm not a fan of doing it implicitly. (This was the real counter-argument I should've made). I prefer to have a single place where input is entirely processed, such as a `from_params(params)`-style constructor. In that constructor you could either coerce, or do anything else with the input prior to passing it through to `.new`.

comment 3y ago · link · parent

> clean architecture has helped me basically not have that be an issue

If you setup your Go app structure like a Rails app structure (basically what clean architecture is), then you have it covered. However, I believe you do have to set it up by hand each time in Go, or write your own generators.

> It is probably good for teams that have "fresh" employees like folks out of college or something to quickly be up to speed without having to hand hold too much.

Architecturally speaking, yes and no. Rails does a lot of non-obvious (to new devs) things for very good reasons, that these devs would have to spend quite a bit of time to understand. Try to write Rails without knowing all the wheres and whys, and you will quickly become frustrated. In Go, you can kinda guide new devs along as you build out most things from scratch. Both of these situations require guidance from experts.

Syntactically speaking, the opposite is true. Ruby lets you write incredibly expressive code by giving you nearly limitless flexibility. In newbie hands this could become a disaster.

It's a common misconception that Rails is beginner-friendly. Its authors have been trying to correct the record on that, by using sharp knife analogies. You have to be very careful with Ruby and Rails, since there aren't nearly the same guardrails as you get with Go.

comment 3y ago · link · parent

Advantages of Rails over Go:

1. REPL. Huge. You can be insanely productive with it. If you're integrating with APIs and therefore dealing with complex nested data structs, you can explore them live. You can explore what's possible with any lib, try things before you write any code. You can also debug errors on the fly as soon as they occurred, right in the browser.

2. Your app is organized around entry points by default. Nobody knows the proper architecture up front for a brand new application. Rails gives you rake tasks for CLI, controller actions for web requests, ActiveJob as a convention for background jobs. You can grow your app's inner architecture over time, but you got all the entry points laid out up front, and they rarely ever change.

3. A lot of built-in security risk mitigation. Cross-site request forgery, encryption for cookies and sessions, convenient encrypted configs and secrets, log filtering functionality, escaping everything by default, and many more. Everything is already handled out of the box.

4. Veteran open source packages (gems) with large companies sponsoring maintenance. Decades of dev and polish on most needed gems, still going.

5. Analytics and monitoring out of the box. Completely wired for tracking performance of everything out of the box. No need to manually integrate performance trackers, just one-line install and you have full profiling capabilities of every part of the app, with many popular dashboard services.

6. Error monitoring out of the box. Many ways to notify exceptions via chats, email, and services, with typically zero integration work.

7. Completely thought-out testing environment out of the box, for both integration and isolated testing. Clean slate on every test without manual setup.

8. Lots of Ruby and Rails tools/functions (e.g. Enumerable) for transforming data via functional pipelines (select, reject, tally, map, take_while, etc) out of the box.

9. Ability to write incredibly reusable code to solve a problem for all data types, not just one particular type (this has gotten better in Go with generics).

comment 3y ago · link · parent

Thanks for the suggestion. I actually explored switching to Attributes for a new Rails app, but 3 reasons made me come back to portrayal gem: 1) attributes don't support defaults. 2) I prefer not to set types on form object attributes, since they are supposed to deal with messy user input. Instead I lean on validations. And 3) I like read-onlyness, freeze, equality, duplication, and introspection features of portrayal gem.

comment 3y ago · link · parent

True. I tend to stay away from gems that try to integrate into multiple parts of your app to provide some sort of comprehensive solution. The kinds of gems I recommend are: 1) libraries (you call into them when you need them) 2) mounted apps on a url, isolated from the rest of your app 3) generators (a nice example: https://github.com/lazaronixon/authentication-zero).

comment 3y ago · link · parent

Not sure why you're downvoted either, it's a legit concern. One way to address it is by being very conservative and picky with gems. A good example is Hey's Gemfile (the app made by Rails creators): https://gist.github.com/dhh/782fb925b57450da28c1e15656779556. It's a good (albeit slightly outdated) example of not straying too far from defaults, while not reinventing the wheel either.

comment 3y ago · link · parent

That said, there are similar objects one can make without using the "form" moniker, for API submissions for example. Granted, I also wish a solution was built-in.
1
141516
19