6 ms·
I love python as well, and I literally just started exploring Nim yesterday, so this is very timely. The one thing that stuck out to me like a sore thumb is th
by khaledh 5y ago
I love python as well, and I literally just started exploring Nim yesterday, so this is very timely.
The one thing that stuck out to me like a sore thumb is the camelCase convention. I know it's a minor thing (and a personal preference), but I'm a bit biased against languages that use camelCase (Java, JavaScript, etc). There's something uneasy about it IMHO.
- osmarks 5y agoIt matches identifiers style-insensitively so you can actually use other conventions if you want. Although the online docs are still camelcased.
- michaelsbradley 5y agoNim is partially case-insensitive: https://nim-lang.github.io/Nim/manual.html#lexical-analysis-identifier-equality https://nim-lang.github.io/Nim/manual.html#lexical-analysis-... my_foo, myfoo, and myFoo are interchangeable. MyFoo is different because the first letter is capitalized. If it's not clear, what I mean is that if you've imported a module that exports myFoo, you can refer to it in your code as my_foo, if you prefer. Some people love this aspect of Nim, others loathe it. I don't have strong feelings about it, though one has to be mindful of it when searching through a codebase with e.g. the_silver_searcher.
- khaledh 5y agoGood to know. Although I'd argue that this is something that I'd count _against_ the language. I'm also biased against languages that allow you to do the same thing in multiple ways (hint: Scala). Code bases tend to vary according to the team's own conventions, so you have to keep adapting to whatever code base you happen to be reading.
- planetis 5y ago--styleCheck:on to enforce the style every identifier is declared in your code base.
- dragonwriter 5y ago> I'm also biased against languages that allow you to do the same thing in multiple ways So you oppose languages supporting both recursion and iteration?
- khaledh 5y agorecursion vs. iteration, inheritance vs. composition, interfaces vs. abstract classes, etc. are design choices that depend on the problem being solved. Language syntax is different; it's an opinion of the language designer which gives the language its distinctive style, and IMO shouldn't have much leeway in expressing the same thing in multiple ways. It's what gives the language its identity. For example, here's how you can iterate over a list in scala to print each element: List(1, 2, 3).foreach(element => println(element)) List(1, 2, 3) foreach { element => println(element) } List(1, 2, 3).foreach(println(_)) List(1, 2, 3).foreach { println(_) } List(1, 2, 3).foreach { println _ } List(1, 2, 3).foreach(println) List(1, 2, 3) foreach (println) List(1, 2, 3) foreach { println } List(1, 2, 3) foreach println
- jjnoakes 5y agoI'm having trouble contrasting that to the many ways I can add 2 and 3, and this doesn't bother me: x = 2 + 3 x = 3 + 2 x = (2 + 3) x = (3 + 2) x = 2; x += 3 x = 3; x += 2 x = 2; x = x + 3 x = 3; x = x + 2
- dragonwriter 5y ago> recursion vs. iteration, inheritance vs. composition, interfaces vs. abstract classes, etc. are design choices that depend on the problem being solved. Recursion and inheritance are interchangeable (in fact, either can be implemented as syntax sugar over the other); while some people find one or the other more natural for a particular problem, there is considerable disagreement among people over which is more natural for which problems. In practice people choose between them based on personal preference and what the language they are using favors (e.g., you probably [0] don’t use recursion unless it is of fairly tightly bounded depth in a language like Python that doesn’t optimize tail calls. > Language syntax is different; it's an opinion of the language designer which gives the language its distinctive style, and IMO shouldn't have much leeway in expressing the same thing in multiple ways. As noted, recursion vs. iteration is exactly a syntax-preference decision, and one on which some languages are highly opinionated (Python) forming an important part of their distinctive style, while others are not. [0] though you could use a tail call optimization decorator
- sp33der89 5y agoI get what you're at with the multiple ways to do stuff, but in Nim it actually makes it more consistent (imo). If my codebase enforces camelCase and a library uses snake_case, then I can still use that library using camelCase, and Nim has nimgrep to make this easier all the way.
- tubbyjr 5y agoYour bias is your own problem. There's clearly a solution that allows you to use snake_case and those that potentially import your library to seamlessly use all exports as camelCase, yet you're still bothered by that. It's nonsensical, Nim literally came up with the absolute most elegant solution to this.
- funny_falcon 5y agoNope. Its solution is "we made things uglier therefore you can mangle them in a way you like". Strong convention is much better than pleasure of everyone.
- planetis 5y ago> we made things uglier That's unfounded, please try it at least once in the playground play.nim-lang.org/. To me it's very cool that wrapped C libs with identifiers like ATOMIC_RELEASE can be written as AtomicRelease without any trouble.
- DangitBobby 5y agoMe too. I do a lot of grepping on codebases and this seems like it could bite me at some point. But it is a very interesting approach to solving the naming convention problem.
- jb1991 5y ago>my_foo, myFoo, and myFoo are interchangeable. I'm confused, two of those are myFoo, so I hope they are interchangeable!
- dragonwriter 5y agoI think it intended my_foo, myFoo, and myfoo.
- michaelsbradley 5y agoFixed. The second or third one should have been all lowercase.
- dunefox 5y ago> my_foo, myfoo, and myFoo are interchangeable. MyFoo is different because the first letter is capitalized. God, that's horrible.
- sp33der89 5y agoEven though it's not according to the styleguide, you can just use snake_case whenever and wherever you want, consumers of your libraries or other way around will never notice!
- khaledh 5y agoThen you end up with an ecosystem with mixed conventions. Not good IMO.
- patrickmn 5y agoYou can literally do whatever you want with any library you use in your own codebase and have a consistent convention in your own code regardless of what your dependencies' authors preferences are. In other words, if the library authors used camelCase but you want to use snake_case in your code, you just do it. It's very strange at first, and I had the same reaction as you, but it's actually quite nice. (I say that as somebody who strongly dislikes snake_case :) )
- elcritch 5y agoSame here, at first making camelCase and snake_case interchangeable seemed like a terrible idea. But in practice I can read and grok libraries that use either and in your code call it using your preference. It just kinda works.
- cma 5y agoYou mean the language is case insensitive and drops _'s or something? Doesn't that break searchability with command line tools (or make for much more complicated regexes)? Or do you just mean use a mixture just like you could in most other languages?
- 0-_-0 5y agoActually, in Nim "functionName", "function_name" and "functionname" are equivalent and interchangeable
- bobbylarrybobby 5y agoOne thing that’s always bugged me about snake case is that people are so averse to the additional length of strings that they just omit the underscores. So you end up with methods like array.tolist() and itertools.ziplongest(*lists, fill_value=None) — that last one isn’t even internally consistent. In an ideal world I would find snake case more readable, but people actually adhere to camel case, which makes it more readable than snake case overall.
- renox 5y agoCamel case consistent? You must be reading different code than me: Ue/UE, Subcell/SubCell, cellgroup, cellGroup all seen in the codebase I work..