Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This reminds me of Joel Splosky's "Making Wrong Code Look Wrong"

https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...

By writing code in a certain way, at a glance you could tell if it's correct or wrong. Most people suggesting making types handle this but that's a level of abstraction. If I have

    v = a + b
If I don't know what a and b are but have to go check their types then I don't know if that code is correct. You could argue if you have good types then of course it's correct but that still misses the point that I don't know what a and b are.

Names help

   html = fieldName + fieldValue
But that's not enough. are fieldName and fieldValue safe? No way to tell here. You could make a SafeString class and that would be good but you're still adding the load that you have to look up the definitions of these variables to know what's going on. The info you need is not here at this line.

Then again, I've never been able to get myself to follow the advice of that article.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: