Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
I have some experience in Defence & Aerospace industry. I am mostly interested in swarm robotics. I like to write about C++ language features and best practices.
I don't use js and this confused the hell out of me at first sight :) i was expecting color to be an element in colors but it is used as an index? I think I prefer the c++ way
The second style (for ... of) is for awaiting inside, or for await ... of.
The third style, I generally use map because of performance, but grammatically, it would be for each. Also, map(async () => ...) can be used with Promise.all (or Promise.allSettled).
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Finally, if you see yourself operating on keys of an Object generically like this, you might instead be looking for Map, which naturally iterates by "entries", and supports non-string keys.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Nevertheless i use many different languages on all my code smells and i like to think them as pseudo code without entering any language details. Your solution is clearly a better one but it is too tied to a particular language.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
The Right JS code is kind of wrong syntax wise and stuff. This would be the correct code:
Or in this case it could have been simplified even further to:
Nice!
I don't use js and this confused the hell out of me at first sight :) i was expecting color to be an element in colors but it is used as an index? I think I prefer the c++ way
inis damn confusing.I also prefer to hide explicit iteration. Still, I had to use the first style for chunking.
The second style (
for ... of) is for awaiting inside, orfor await ... of.The third style, I generally use
mapbecause of performance, but grammatically, it would be for each. Also,map(async () => ...)can be used withPromise.all(orPromise.allSettled).In my opinion chinking should be hidden at iteration level.
That is, if a convenient library function exists.
ofwith iterators,inis for string keys of objects (including inherited).for inandfor ofsyntax in js looks likefor (const ident of expression)(whereconstcould beletorvarandofcould bein))in the last statementconsole.logArraymethod is calledforEach(capitalization)so, all in all:
if for some reason you have to use
into iterate over values of an object, it's typically done like this (to avoid iterating over inherited keys)however you should prefer the new iterators, such as
Object.keys(),Object.values()andObject.entries().As such, the above becomes:
Finally, if you see yourself operating on keys of an Object generically like this, you might instead be looking for Map, which naturally iterates by "entries", and supports non-string keys.
See also Set, WeakMap, WeakSet
Wow!
How many detaill!
I will make your corrections
Nevertheless i use many different languages on all my code smells and i like to think them as pseudo code without entering any language details. Your solution is clearly a better one but it is too tied to a particular language.
What other languages do you use?
see my code smells
up to now:
javascript
pyhton
php
golang
java
ruby
Language is accidental
Code smells are not related to any particular language
I write code snippets as examples but I think them most as pseudocode