Live data from Hacker News

Can You Find the Bug in This Code?

victorzhou.com

11–20 of 64 posts

Re: Can You Find the Bug in This Code?

#11

I feel good that my first thought of fixing it would have created the solution. There were obvious errors in my mind that I would fix without knowing the whole dissertation on why it happened. So maybe if the question was, "Can you repair this code", I would excel.

Ditto. I didn't know it was a missing semicolon, but the code smells bad regardless and my solution also would have solved it another way (just by improving code readability/clarity).

It is likely one of these "trust your gut" situations.

Re: Can You Find the Bug in This Code?

#13

Always prepend ( and [ with ; I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.

I'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.

Re: Can You Find the Bug in This Code?

#17
post #10

I refuse to use semi-colons in TS/JS, unless that conflicts with existing code standards. I feel like it's as if I'm using semi-colons in Go. This can easily be avoided by writing clearer code.

Relevant: https://standardjs.com/rules.html#semicolons (hint: no semi-colons!)

Re: Can You Find the Bug in This Code?

#19
post #13

Always prepend ( and [ with ; I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.

I'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.

More correctly it's:

Always prepend any line that begins with ( and [ and ` with ;

Re: Can You Find the Bug in This Code?

#20
post #13

Always prepend ( and [ with ; I also prefer void function () {} for this. Void the result of this function expression which I immediately invoke.

I'm not sure always prepending those with ";", but definitely when needed, sure. But most of the time you can simply refactor the code a little bit and improve readability with the addition of a single variable.

Always for ( and [ when they start a statement.

It really is that simple.

Post reply on HN