cdruc

thoughts and notes

Page 2 of 2

Cost is no object. No, that’s too much money.

Driving home from a mini-trip, one of my friends was testing product ideas bouncing them with the rest of us. Most of them were turned down because the financial part wasn’t appealing enough. Like who’s gonna pay 20$ for this product? I wouldn’t – most replied.

I wouldn’t pay 1200$ for a Kanye’s anything. None of his products are worth that much – for me. And I love Kanye.

But people value things differently. There are people willing to pay 8 million dollars for a phone.

The ones buying it don’t do it for the tech (it’s an iPhone 4 after all), for the gold, platinum, or diamonds.

They do it because they want to be the ones with the 8 million dollar phone.

Cost is a factor, but most of the times it’s just another excuse.

The programmer’s gut feeling

Whenever you feel like an object isn’t really what the name says it is, or that it shouldn’t exist, or that it should exist, but in a different shape, you are completely right.

Stop and re-think things through. Maybe what you find is that you don’t really need that object. Or maybe what you’re trying to accomplish needs two or more objects or an existing one.

That gut feeling telling you that something isn’t what you think it should be is always right.

A Parameter doesn’t have a ParameterRecommendation. The parameter value has a recommendation.

Wrong. We can have n variations of parameter values – we shouldn’t have a different recommendation for the slightest variation.

But we can have some pre-defined ranges. ParameterRange has recommendations.

When cutting

You find a way to eat fewer calories and you stick with it until you reach your fat loss goal. Restricting calories is painful, sometimes annoying, but not the hardest thing to do.

The hardest thing is watching your strength fade away.

Minimizing muscle loss is part of the goal, and we fight it by lifting heavy; sets of five to seven reps. And because of that, we often get injured. Not the kind of injuries to keep us out of the gym, but painful enough to be noticed.

Those are messages. Messages from your body telling you to take it easier, to lower the weight.

You should listen.

The price we pay

Although dedication and patience are the most valuable currencies when working on transforming your body, this post is not about that cost. It’s about the actual money we spend, in a form or another.

A membership to a decent gym is about $50/month. You want a personal (shared) trainer, add another $70. That gets you to $120/month or $1440/year.

Apart from gloves, clothing, and good footwear, you also need to consider the time invested. An average workout, unless you’re going to group training, is about 1.5-2 hours. Add at least half hour to get to and back from the gym, and then another half hour to get your shower. That totals to about 3 hours.

You go to the gym four days a week, that’s 12 hrs/week or 48 hrs/month.

Naming things is hard…

Coming up with clear, expressive and precise names can be challenging and sometimes even infuriating. Why can’t I name this damn thing!? 

We grab our best friend, the thesaurus, and we start digging, jumping from one result to another. And we do that until we find the best word for the thing we’re trying to name.

But finding good names takes time, so I made something the other day that will make you a bit faster. It’s an app for the other programmer’s best friend, the command line. I call it sini and you can find it here.

 

Are these seconds, minutes, hours? Add some meaning to your time units calculations

Apart from a small todo-cli app and a laravel framework bugfix, I have nothing to show in terms of open source contributions. I’ve always dodged contributing and there are more than enough reasons for that. But the truth is I was mostly hiding behind the “I don’t have time” and “I don’t have a good enough idea” excuses.

But that ends today. Recently I stumbled upon a tweet from Freek (do follow, lots to learn from) asking if there’s a package to convert different time units and assign some meaning by escaping the use of magic numbers when returning stuff like 60 * 12.

The suggested API, Minutes::fromHours(5) is a lot clearer and has more meaning than a random math operation but it implies having separate classes for each time unit. It also prevents me from doing any further conversions on the same value.

Since I’ve never published a php package before, and I was curious about the whole process, I went ahead and created druc/time-convert. It contains a single class and you can do stuff like $time = TimeConvert::hours(5)->toMinutes() and also continue with further conversions like $time->toSeconds().

I’m sure is the smallest and most trivial php package out there, but at least I got to learn the publishing process. 🙂

Help me and others understand your code

It’s hard to make things work. But it’s even harder to explain how you did it. Here are a few things you could do to help me, you, and others understand your code.

Good formatting. Yes, that space between operators is important. Line lengths, line breaks, blank lines, camelCase, snake_case — they all make a difference. Be consistent, adhere to a guide.

Careless naming. Don’t use abbr. Don’t make me guess. Don’t mislead. Be precise. What is it? What does it do? Why it exists?

Conditionals and switch statements produce different outcomes. Which means I have to read the code again, and again, and again…

Nested loops, nested loops with conditionals 😮 . Same as above, only a million times worse. Get rid of them.

Hide stuff I don’t need to know. I don’t need the details. I want to be able to say “ah, it does this” without knowing exactly how. Write in cascade. Start with high-level concepts and add more details as you go downstream.

Make smaller things. It increases the number of files, classes, and methods and makes it harder to reason about the whole system. But that’s the idea. I don’t want to reason about the whole system. I can’t. Nobody can. I’m more efficient reasoning about small things. One at a time.

Don’t fall into the “I’m the only one working on this” trap. There are at least two people working on a project during its lifetime. The first one is you. The second is the you after a few months.

Put some more care into your code. Name stuff a little better, split classes and methods into smaller ones, make it look and read well.

It's not your code. It's our code.

About those “would be nice if…”s

New project. We have our meetings, we come up with a plan, we somehow agree to a budget and then we get the ball rolling, coding our way to the finish line.

As we build stuff, fresh requirements are sent in. “We need this new feature”, “we haven’t thought of that”, “it would be nice if…”, etc. And it’s ok. We saw this coming.

Displaying that list on two columns, making those elements editable, changing that color, size, font, whatever — they seem to have such a low value that we often neglect them. But they pile up and sometimes affect the system in ways you wouldn’t expect, taking an even bigger dip in the budget.

We are bad estimators. But that’s not the worst part. The worst part is that we rarely, if ever, say no to a client.  One reason, apart from the customer is always right and make the client happy, is that it would make us feel incapable, unworthy of our profession. We take saying no as something to be embarrassed of. It’s not.

Saying no not only leaves you with fewer things to do but also leads to a major increase in productivity. It’s far easier to stay focused when you don’t have to worry about the “would be nice if”s.

The devil’s in the details. Control the scope.
Focus on what is essential to create value now. Add the rest later.

Work at the smallest scale possible

You know that feeling when you found an elegant solution to a problem you’ve been having? You discovered that pattern you’ve been missing and you’re like “yeah! now I get it!”.

The excitement gets the worst of us and we start acting like the thing we found is the holy grail of software writing.

Like yes, this looks way better. If I apply this pattern here and use this structure there, all my problems go away. And we sprinkle all that over our project.

A few days go by and we’re like “wait a minute…this solves my problem but complicates this other thing I’m working on. Fuck..”.

We fiddle around with it for a few hours, sometimes days, and then we either find a way to patch things up or we hit the undo button and start from scratch.

The thing we found has its use. Where we go wrong is trying to force use it everywhere.

Hello world!

I read, watch and listen every day.
I have trouble remembering things – it’s time to write stuff down.

Page 2 of 2

Powered by WordPress & Theme by Anders Norén