So I have node.js application that exposes some API to clients and connects to some SQL database. First let introduce some premises:
Problem is because javascript standard/practice is using camelCase which I would like to keep.
So as I see there are 3 solutions:
So what do you suggest? Mine favorite is first solutions but if you have some other smart ideas not mentioned here please feel free to tell.
Besides, the only reason Node uses camelcase is because Javascript's own default API (from the 1990s) uses it.
camelCase is used by JavaScript itself, by jQuery, and other JavaScript libraries. Do not start names with a $ sign. It will put you in conflict with many JavaScript library names.
Snake case (also referred to as underscore case) is when all the letters of the word are lower case but delimited by an underscore. We seldom use the snake case coding convention in C-style languages like Java, JavaScript, and TypeScript.
Screaming snake case is used for variables. Scripting languages, as demonstrated in the Python style guide, recommend snake case in the instances where C-based languages use camel case.
As Occam's razor principle says, the simplest solution is the best one.
If you have client's requirements on the one hand and node.js code style guides on the other hand. I would take the simplest solution satisfying the both. External API should be snake case and internally you can use camel case. If you stick to consistency you can use snake case everywhere, as I assume client's requirements have higher priority.
I would really avoid any additional layers for converting cases as it introduces additional complexity to the final solution, it can have additional errors, and it will require additional maintenance in the future.
Personally, when I have to deal with snake case in javascript, I use it only with square brackets:
data['user_id'] = 1;
so, technically I don't violate any style rules: these are just strings, not identifiers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With