Hacker News new | ask | show | jobs
by geraldalewis 5330 days ago
I've been experimenting with being a joyful and optimistic programmer, and I feel a real difference when I code.

At first, I started with little things, like leaving semicolons out of my JavaScript. I understand the subtle bugs that may manifest from automatic semicolon insertion, but I've yet to have a problem, and I really love the aesthetics.

I work a lot in a language that supports gradual typing, but I and many other devs fall victim to "type guilt" and annotate everything. I started omitting types where they wouldn't offer a performance benefit, or work as documentation.

You know how you're always supposed to store an Array's length in a `var` when looping with a `for` statement? That way you don't waste cycles every iteration re-evaluating the Array's `length`? If my Array has only a few elements, I'll save myself from the clutter of declaring a new variable and just use `array.length` in my condition. Wild, I know.

Does every function need to be littered with `assert`s? Does every program need 100% coverage? Isn't there room for free-thought where there's a best-practice?

1 comments

You know how you're always supposed to store an Array's length in a `var` when looping with a `for` statement?

In this case, why not use the 'foreach' or iterator paradigm?

IMO, It's brain dead that programmers have to worry about such details in the first place. It is the task of the programming language to automate best practices that can easily be automated, and to not have to state them every single time. That increases overall productivity and also reduces bugs/mistypes.

> why not use the 'foreach' or iterator paradigm?

I totally agree, and I do use when it's available in a given lang I'm working in/it's not overly cumbersome (some implementations miss the point).