My version would have these differences:
- using 2 spaces instead of Tabs for indentation
- not using "~" for variable names. Question: why is this a thing? After the "fun" I had debugging the problem of using $ in a calc field variable, I would argue "don't use any punctuation at all" especially since ~ and $ are visually a little bit similar.
- no space before leading parenthesis
- all Case clauses on a single line
- no space before opening "(" in a function call, but spaces are OK to separate function parameters).
- no space before trailing semicolon (though I don't feel strongly about this)
- I would replace the not IsEmpty() function with a ≠ "" comparison, since I think double-negatives are hard to reason about, and I think it's fun to type unicode characters in code, though I regret it later when I try to type ≠ in some other language...
- add a comment with hints and todos and some history
Here's how it would look in my style
/* Convert a specific asset category to a parent category.
Returns "Error:..." if no match
TODO: these values should not be hard-coded here, but rather should
live in a related table, lookup, or value list for a more data-driven design.
History:
20230101 XMZ created, because Bob needed this for client X
20230201 SBF fixed the bug where Poodles were showing up as "Office Eqiupment"
*/
Let(
[
coCategory = Assets::Category;
compSoft = "Software¶Workstations¶Un-Used Computers¶Servers";
offEquip = "Camera¶Printers¶Hardware¶Monitors";
furn = "Furniture";
cityCategory = Case(
FilterValues(compSoft ; coCategory) ≠ "" ; "Computer & Software";
FilterValues(offEquip ; coCategory) ≠ "" ; "Office Equipment";
FilterValues(furn ; coCategory) ≠ "" ; "Furniture, Fixtures & Leaseholds";
"Error: Missing Category"
)
] ;
cityCategory
)
Edit: many edits as I thought of more ideas.