Genuine question: do you feel like performance is even a concern here? The difference between these operations is probably literally nanoseconds unless you have enormous arrays. What do you think of the readability/code clarity trade-offs between these options?
Performance should always be a concern. Sure, in a single example like this, it seems petty to harp on that one has to use the fastest code ever. But remember that code will almost always be a series of statements.
Consider if the code was littered with the least efficient versions of operations. Methods would take longer to complete, and thus the application would appear slow. And isn't the ultimate goal of software to help humans do things faster (as fast as possible)? :-)
I agree that all things being equal performance should be important. Things are rarely equal though, and in this case I was making a point that I feel that readability matters much more in this situation.
Put another way: people are definitely going to have to read your array clearing code if you write it, so readability is going to be a concern. How many of these array clearing operations do you think it would take to make a noticeable difference in your app's performance? I feel like it would have to be millions.
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I come from the generation where every byte counted and I know that optimisation sometimes seems like a lost art, but having something that you can understand without having to scratch your head for a second is more important in almost every situation.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Genuine question: do you feel like performance is even a concern here? The difference between these operations is probably literally nanoseconds unless you have enormous arrays. What do you think of the readability/code clarity trade-offs between these options?
In my opinion, yes.
Performance should always be a concern. Sure, in a single example like this, it seems petty to harp on that one has to use the fastest code ever. But remember that code will almost always be a series of statements.
Consider if the code was littered with the least efficient versions of operations. Methods would take longer to complete, and thus the application would appear slow. And isn't the ultimate goal of software to help humans do things faster (as fast as possible)? :-)
I agree that all things being equal performance should be important. Things are rarely equal though, and in this case I was making a point that I feel that readability matters much more in this situation.
Put another way: people are definitely going to have to read your array clearing code if you write it, so readability is going to be a concern. How many of these array clearing operations do you think it would take to make a noticeable difference in your app's performance? I feel like it would have to be millions.
I come from the generation where every byte counted and I know that optimisation sometimes seems like a lost art, but having something that you can understand without having to scratch your head for a second is more important in almost every situation.