A space to discuss and keep up software development and manage your software career
An inclusive community for gaming enthusiasts
News and discussion of science and technology such as AI, VR, cryptocurrency, quantum computing, and more.
From composing and gigging to gear, hot music takes, and everything in between.
Discussing AI software development, and showing off what we're building.
A general discussion space for the Forem community. If it doesn't have a home elsewhere, it belongs here
Movie and TV enthusiasm, criticism and everything in-between.
Memes and software development shitposting
Web design, graphic design and everything in-between
A community of golfers and golfing enthusiasts
A community for makers, hobbyists, and professionals to discuss Arduino, Raspberry Pi, 3D printing, and much more.
Your central hub for all things security. From ethical hacking and CTFs to GRC and career development, for beginners and pros alike
For engineers building software at scale. We discuss architecture, cloud-native, and SREโthe hard-won lessons you can't just Google
Discussing the core forem open source software project โ features, bugs, performance, self-hosting.
A collaborative community for all things Cryptoโfrom Bitcoin to protocol development and DeFi to NFTs and market analysis.
Great post, I like how you took the time to explain step by step.
I'd suggest also the following change to make the "business rules" clearer by extracting them from the formatting logic:
const formatMap = { uk: ["zip", "suburb", "city", "state"], us: ["city", "state", "zip"], nz: ["zip", "city", "county", "state"], default: ["zip", "suburb", "state", "county"], } const formatAddress = (address) => { const format = formatMap[address.countryCode] || formatMap.default; return format.map(field => address[field]).filter(Boolean).join(', '); };
this is nice.. considering formatMap value can be saved in config file or database. Its easier to scale.
This is the final image in a magneto_perfection.jog meme. I love it.
Well one way or another the formatAddress function needs to know the business rules. If I went with your approach I would pass the rules as an argument.
formatAddress
this is also what i like to do whenever a switch case appears
Unless formatMap is something that needs to be dynamic, I suggest not to do this.
This mixes up type and data and also smells like premature abstraction.
Actually Iโve just written a post about this kind of pattern, if youโd like to take a look: dev.to/tomazlemos/keeping-your-cod...
Thanks for sharing this. ๐
Iโd never seen this pattern in JS, looks just as nice as in Java ๐๐ผ๐๐ผ
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
Great post, I like how you took the time to explain step by step.
I'd suggest also the following change to make the "business rules" clearer by extracting them from the formatting logic:
this is nice.. considering formatMap value can be saved in config file or database. Its easier to scale.
This is the final image in a magneto_perfection.jog meme. I love it.
Well one way or another the
formatAddress
function needs to know the business rules. If I went with your approach I would pass the rules as an argument.this is also what i like to do whenever a switch case appears
Unless formatMap is something that needs to be dynamic, I suggest not to do this.
This mixes up type and data and also smells like premature abstraction.
Actually Iโve just written a post about this kind of pattern, if youโd like to take a look:
dev.to/tomazlemos/keeping-your-cod...
Thanks for sharing this. ๐
Iโd never seen this pattern in JS, looks just as nice as in Java ๐๐ผ๐๐ผ