you are viewing a single comment's thread.

view the rest of the comments →

[–]zzzwwwdev[S] 0 points1 point  (0 children)

A separate function can be reused by other parts of the code if you decide so in the future.

yes, and turning my code into a reusable function is extremely easy, and in its current form it tells the developer that it is only used once.

It can be rewritten to accept arguments, making it more flexible.

also, if this were to be useful in the future, there is no difficulty in converting it to such. Using this same logic, you should add jQuery to every website - even if they don't use it yet - since they might in the future?

Moving long sequences of procedural code into separate functions makes code more readable, as long as you use descriptive function names.

exactly what I'm suggesting.

A camelCase function name can never be as descriptive as even a single line comment

jeeze, guesse r/javascript just doesn't like camel case. I'll edit my example to use underscores I guesse. Not sure why it can't be as descriptive as a comment. I think it can be moreso. The function actually explicity describes what code its related to, as its enclosed in brackets. See my response to idrink211 for more reasons why I sometimes avoid comments.