For my current project I use the JS backend. I checked how the generated JavaScript looks, because at some stage we might need to maintain the JaavScript output without the Nim source.
So it is good that the JavaScript code is fairly readable, however all function names (plus other identifiers have numbers at the end. Here the beginning of an entry point function as an example:
function process_file_14435037(event_14435039) {
var content_14435044 = newStringStream_11860214(cstrToNimstr(reader_14432014[0].result));
var tl_14435045 = newTableLayout_14175143();
...
Is it possible to get rid of the number part if the name is unique without the number?
I checked how the generated JavaScript looks, because at some stage we might need to maintain the JavaScript output without the Nim source.
Why would you ever do that... It's one of the worst ideas I've ever come across. For a start, the Nim source has valuable type information, the generated JS loses this information.
I expected a comment like this... :-)
The whole situation is not ideal, of course, but other people (very occasionally) will need to maintain the code after I hand over the project - and other people in the organisation are no Nim fans - yet. ;-)
and other people in the organisation are no Nim fans - yet. ;-)
I can assure you they will be even less fans of the generated JS output from Nim...
When developing a web app in Nim, you shouldn't look at the generated JavaScript, just like you don't > look at the generated C when developing a native program in Nim.
For simple todo app, sure.
This could be default way for generating var names, at least those which are not derived
I think, at least it would be great to have an option that all names are generated as is without the trailing number.
Because it's pretty painful to add {.exportc.} to many declarations if you want lots of symbols unmangled...
ps: {.push exportc.} ... {.pop.} seems to work only on top level symbols (e.g. a let in a function will still be mangled despite a {.push exportc.} ... {.pop.} "bracket" around the function).
Well the issue with always outputting the proper name is in Nim we have types, JS doesnt so the following code is valid in Nim.
proc test(a, b: int) = discard
proc test(a, b: float) = discard
both output:
function test(a,b){}
At first glance we could use the types!
So the identifiers would be testInt and testFloat, but then say we declare proc test(a: int). We could then use the types of each parameter! So now we have testIntInt.
Now say you have a procedure with the signature proc test(a, b: var int) = discard. Hmmm..... we can prefix the types with var so now we have testVarIntVarInt ah yes the glory of a readable distinct JS function name!
Very good point. Didn't think of it.
So, I guess - for good reasons - it is what it is.
When developing a web app in Nim, you shouldn't look at the generated JavaScript, just like you don't look at the generated C when developing a native program in Nim.
Disagree. If you are using JS, there are high chance that you going to need some JS libraries. And the simple the integration going to be the better.