snowberb – 10-49 Oct 6
Focusing only in code readability, maintainability and quality, which piece of code would you choose? (Both do the same and work)
The objective is to calculate the bounds of a point chart
Piece 1:
Piece 2:
6 Replies
what about
yeah that's way better
I often overcomplicate and I dont know how to improve on that
@⛄Snowberb⛄ oh, second example is IMO way more difficult to understand and it's longer 😄 Evert gave nice code with
Math.min
and Math.max
instead of conditions
Although I think that yours first example, with replaced if
s to mentioned Math methods would be better than Evert's example, because there would only be 1 loop 🤔
And you should avoid using for..in
for arrays - use for..of
instead and you can destructure stuff directly at the iterator declarationfor single loop you could do
if it's actually faster you'd have to profile
Faster or slower doesnt matter here
I know I gave this without context, but taking into account the findMinMax function already exists and is used in other places of the project
I do think it's way more readable than the first example, and what is most important, it's rehusable and maintainable
but yeah with the min max math functions is the best way of doing this
the shortest and the clearest
This thread hasn’t had any activity in 36 hours, so it’s now locked.
Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1159804662548013056