News for hackers. Stuff that matters.
Re:Nim 2.0 thoughts by khaledh on Saturday May 15, 2021 @11:24AM (#27166017)
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.

Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @11:29AM (#27166061)
Nim is partially case-insensitive:

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.

Re:Nim 2.0 thoughts by khaledh on Saturday May 15, 2021 @11:34AM (#27166122)
Good 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.
Re:Nim 2.0 thoughts by tubbyjr on Saturday May 15, 2021 @12:38PM (#27166702)
Your 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.
Re:Nim 2.0 thoughts by funny_falcon on Monday May 17, 2021 @09:40AM (#27183243)
Nope. 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.

Re:Nim 2.0 thoughts by planetis on Monday May 17, 2021 @12:42PM (#27185424)
> 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.

Re:Nim 2.0 thoughts by sp33der89 on Saturday May 15, 2021 @11:52AM (#27166295)
I 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.

Re:Nim 2.0 thoughts by planetis on Saturday May 15, 2021 @11:39AM (#27166169)
--styleCheck:on to enforce the style every identifier is declared in your code base.
Re:Nim 2.0 thoughts by DangitBobby on Saturday May 15, 2021 @04:46PM (#27168864)
Me 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.
Re:Nim 2.0 thoughts by dragonwriter on Saturday May 15, 2021 @11:42AM (#27166209)
> 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?

Re:Nim 2.0 thoughts by khaledh on Saturday May 15, 2021 @12:08PM (#27166438)
recursion 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
Re:Nim 2.0 thoughts by jjnoakes on Saturday May 15, 2021 @12:45PM (#27166760)
I'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
Re:Nim 2.0 thoughts by dragonwriter on Saturday May 15, 2021 @01:23PM (#27167093)
> 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

Re:Nim 2.0 thoughts by funny_falcon on Monday May 17, 2021 @09:45AM (#27183296)
> Recursion and inheritance are interchangeable (in fact, either can be implemented as syntax sugar over the other)

Did you mean Recursion and Iteration?

Some recursion could be translated into iteration only if there is stack managed by hands. It decreases readability significantly.

Simplest example: Ackermann function.

And it works both way: some algorithms are better read as iteration.

Re:Nim 2.0 thoughts by dunefox on Saturday May 15, 2021 @03:25PM (#27168108)
> my_foo, myfoo, and myFoo are interchangeable. MyFoo is different because the first letter is capitalized.

God, that's horrible.

Re:Nim 2.0 thoughts by jb1991 on Saturday May 15, 2021 @11:36AM (#27166144)
>my_foo, myFoo, and myFoo are interchangeable.

I'm confused, two of those are myFoo, so I hope they are interchangeable!

Re:Nim 2.0 thoughts by dragonwriter on Saturday May 15, 2021 @11:40AM (#27166182)
I think it intended my_foo, myFoo, and myfoo.
Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @11:40AM (#27166183)
Fixed. The second or third one should have been all lowercase.
Re:Nim 2.0 thoughts by bobbylarrybobby on Saturday May 15, 2021 @06:37PM (#27169624)
One 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.
Re:Nim 2.0 thoughts by renox on Sunday May 16, 2021 @12:36PM (#27174837)
Camel case consistent? You must be reading different code than me: Ue/UE, Subcell/SubCell, cellgroup, cellGroup all seen in the codebase I work..
Re:Nim 2.0 thoughts by sp33der89 on Saturday May 15, 2021 @11:33AM (#27166119)
Even 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!
Re:Nim 2.0 thoughts by khaledh on Saturday May 15, 2021 @11:35AM (#27166139)
Then you end up with an ecosystem with mixed conventions. Not good IMO.
Re:Nim 2.0 thoughts by patrickmn on Saturday May 15, 2021 @11:51AM (#27166287)
You 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 :) )

Re:Nim 2.0 thoughts by cma on Saturday May 15, 2021 @09:39PM (#27170498)
You 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?

Re:Nim 2.0 thoughts by elcritch on Saturday May 15, 2021 @07:33PM (#27169911)
Same 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.
Re:Nim 2.0 thoughts by 0-_-0 on Saturday May 15, 2021 @03:21PM (#27168070)
Actually, in Nim "functionName", "function_name" and "functionname" are equivalent and interchangeable
Re:Nim 2.0 thoughts by lenkite on Saturday May 15, 2021 @10:05PM (#27170612)
So one needs to grep 3 times instead of once in a code-base. Why did the authors chose this abominable convention ? It makes maintenance a nightmare.
Re:Nim 2.0 thoughts by nimmer on Sunday May 16, 2021 @07:37AM (#27172959)
I never had this issue: do not mix different stiles across the same project.

Instead, you can import and use libraries that use a different stile without breaking your convention.

Re:Nim 2.0 thoughts by planetis on Sunday May 16, 2021 @04:48AM (#27172242)
nimgrep solves this, you might not like it, but people who have actually tried it are fond of it.
Re:Nim 2.0 thoughts by osmarks on Saturday May 15, 2021 @11:28AM (#27166056)
It matches identifiers style-insensitively so you can actually use other conventions if you want. Although the online docs are still camelcased.