Idiomatic or idiosyncratic? by Mark Seemann A strange programming construct may just be a friendly construct you haven't yet met. Take a look at this fragment of JavaScript, and reflect on how you feel about it. var nerdCapsToKebabCase = function (text) { var result = ""; for (var i = 0; i < text.length; i++) { var c = text.charAt(i); if (i > 0 && c == c.toUpperCase()) { result = result + "-"; } result = result + c.toLowerCase(); } return result; }; Do you understand what it does? Does it feel appropriate for the language? Does it communicate its purpose? Most likely, you answered yes to all three questions - at least if you know what NerdCaps and kebab-case means. Would your father, or your 12-year old daughter, or your English teacher, also answer yes to all of these questions? Probably not, assuming they don't know programming. Everything is easy once you know how to do it; everything is hard if you don't.
Read full article from Idiomatic or idiosyncratic?
No comments:
Post a Comment