tag:blogger.com,1999:blog-34454975.post4419561247389588341..comments2023-06-28T16:58:41.189+02:00Comments on Web Reflection: Some Common Web NonsenseAndrea Giammarchihttp://www.blogger.com/profile/16277820774810688474noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-34454975.post-69428571992510497532013-01-05T00:39:21.390+01:002013-01-05T00:39:21.390+01:00All good refactoring but I especially like the bit...All good refactoring but I especially like the bitwise example. That was "The Way It Was" for C programmers; a dev could recognize a bitmask pattern as easily as JS devs can recognize "obj.prop = obj.prop || someVar". Shame it fell out of use, but it is definitely a good one.HBhttps://www.blogger.com/profile/12810119061565239296noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-36638536636795714162012-11-07T18:57:33.724+01:002012-11-07T18:57:33.724+01:00maybe your code could make more sense, becoming mo...<i>maybe your code could make more sense, becoming more readable, easier to maintain</i><br />Really?! By using bitwise operators where a logical expression is expected? Rule of thumb is not to use "not common" solution in common places like these. Also bitwise operators are very rarely used in JS with a good reason: all the numbers are represented as "double"s and when bitwise operators are used on them they are converted to integral representation.<br /><br />I think code "makes more sense" is "more readable" and is "easier to maintain" if you use 'boolean' expressions where boolean expressions are expected and keep the bit-operation magic for those places where you actually want to do bit operations.<br /><br />Your last example is actually a reasonable one for using bitwise operations :)foldiphttps://www.blogger.com/profile/15738626993756644959noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-38226436152591669702012-11-05T17:35:35.604+01:002012-11-05T17:35:35.604+01:00that one yes but there is no way to optimize obj.p...that one yes but there is no way to optimize obj.prop = obj.prop || defValue; which is the case mentioned in this postAndrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-86377814734972876082012-11-05T17:21:19.880+01:002012-11-05T17:21:19.880+01:00No, I didn't say Facebook because you work the...No, I didn't say Facebook because you work there... I believe you work at Facebook because you care about such things.<br /><br />I still think that a <br /><br />variablename = variablename || scalarvalue<br /><br />can be easily recognized, and either optimized automatically, or at least, spotted by a linter like jslint or jshint.Aadaamhttps://www.blogger.com/profile/05843560041038857258noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-87460937049444615982012-11-04T19:49:24.204+01:002012-11-04T19:49:24.204+01:00The reassign for no reasons cannot be optimized by...The reassign for no reasons cannot be optimized by JIT because it's a valid operation with intents. Object.observe() will have problems because of that pointless operation, or better... the code using it will have problems, no matter who or how many wrote the code. Last, but not least, I don't talk about my job, team, company I work for here... since ever ! I represent myself, with my thoughts, and nothing else.Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-55461787963533335232012-11-03T23:08:18.953+01:002012-11-03T23:08:18.953+01:00The problem is, and will be, that as the lingua fr...The problem is, and will be, that as the lingua franca of the web, JS won't be developed by just you and me and a few others who dedicated a fair bit of our time understanding how it works.<br /><br />The web will be developed by a lot of people who just don't care.<br /><br />(Personally, I usually apply all the options from a config object in a for in cycle, using hasOwnProperty, which makes it quick, although I haven't written a single line of prod code since last June)<br /><br />But in general, the the job of a compiler, wether it is a minifier, a cross-language compiler or the built-in compiler of a JIT VM, is to make sure that people who know the tricks, who know deeply and care about the underlyings of the language make the optimizations.<br /><br />So no, I don't say such needs to be in the compiler because I'm lazy: I'm aware not all the things can go into the compiler and we should care and if we're unsure on which construct to use, we either have to check VM sourcecode, or simply run jsperf tests.<br /><br />But most people won't do this. They'll just put in whatever comes into their mind. Engineers of big JS-based application providers, like Facebook, yes, they have to care about it, as hundreds of millions of people depend on this every single day.<br /><br />But for the others, it has to be a language feature.<br /><br />Besides, wether we like it or not, the original || notation on setting the property makes the intent clear even to someone who has no knowledge of the underlying hash implementation of JS objects, but has some knowledge of C-style languages in general.Aadaamhttps://www.blogger.com/profile/05843560041038857258noreply@blogger.com