News for hackers. Stuff that matters.
Re:Nim 2.0 thoughts by adenozine on Saturday May 15, 2021 @11:04AM (#27165823)
Potentially unpopular opinion, please go easy on me, I'm a python lover:

I find a lot of Nim syntax just unnecessarily noisy. I wish that it had stuck much closer to Python syntax.

I'm really excited about Nim, don't get me wrong. I like Araq, he's got a real hacker spirit not oft found at the head of big projects.

Anyhow. I'm sure the experts in that topic will sort it all out. ORC is wildly impressive all around.

Re:Nim 2.0 thoughts by xioren00 on Saturday May 15, 2021 @11:07AM (#27165864)
Static typing aside, I don't find it any more verbose (noisy) than Python. In fact I find it strikes a perfect balance.
Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @11:06AM (#27165854)
Can you give an example of noisy syntax? Is it in relation to the type system?

I'm writing Nim every day recently; I haven't experienced it being noisy, but I also don't have extensive or recent experience with Python.

Re:Nim 2.0 thoughts by adenozine on Saturday May 15, 2021 @11:27AM (#27166047)
Sure.

I'm on phone, so hopefully this paste doesn't look awful, but it's right from the website homepage

iterator oddNumbers[Idx, T](a: array[Idx, T]): T = for x in a: if x mod 2 == 1: yield x

The three different sets of brackets, the mixed : and =, it just seems inelegant to me.

I don't really know how I'd improve it, so it's just pointless, ignorant complaining on my part. Pay me little mind.

Re:Nim 2.0 thoughts by xigoi on Saturday May 15, 2021 @11:35AM (#27166134)
The equivalent in Python would be:

  T = TypeVar("T")
  def odd_numbers(a: list[T]) -> Iterator[T]:
      # implementation
I don't really find that less verbose, in terms of brackets and symbols…
Re:Nim 2.0 thoughts by adenozine on Saturday May 15, 2021 @11:57AM (#27166344)
Yeah, I guess you're right.
Re:Nim 2.0 thoughts by memco on Saturday May 15, 2021 @01:55PM (#27167372)
Does Nim have comprehensions? Even if you're striving for equivalent signatures the inner body of the function can be expressed as a comprehension in Python:

  T = TypeVar("T")
  def odd_numbers(a: Iterable[T]) -> Iterator[T]:
    yield from (n for n in a if n % 2 == 1)
Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @02:18PM (#27167568)
Re:Nim 2.0 thoughts by nerdponx on Sunday May 16, 2021 @07:56AM (#27173045)
I think the "full" version is easier to read:

    T = TypeVar("T")
    def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
        for n in nums:
            if n % 2 == 1:
                yield n
Although yet another option is to just return the generator instead of immediately yielding from it:

    T = TypeVar("T")
    def odd_numbers(nums: Iterable[T]) -> Iterator[T]:
        return (n for n in a if n % 2 == 1)
Re:Nim 2.0 thoughts by xigoi on Saturday May 15, 2021 @05:58PM (#27169396)
Unfortunately, Nim doesn't have `yield from`, which would make a comprehension useless here. That's one of the things I'm missing in the language.
Re:Nim 2.0 thoughts by planetis on Sunday May 16, 2021 @04:50AM (#27172260)
That's an obscure/not optimal way to write this code though. I mean why would you use LIST comprehension if you are going to yield each element.
Re:Nim 2.0 thoughts by nerdponx on Sunday May 16, 2021 @07:56AM (#27173050)
It's not list comprehension, it's generator comprehension, which is lazily computed. However it's still an unnecessary layer of iteration, when you could just return the comprehension instead.
Re:Nim 2.0 thoughts by WesolyKubeczek on Saturday May 15, 2021 @11:28AM (#27166055)
I can't get used to the fact that for builtin types grow methods, you need to import corresponding modules everywhere.

You import module X, which gets you objects as defined in the module Y. To use methods defined for that type, you need to import Y yourself. Python, of course, by virtue of binding objects to methods, doesn't need it.

There are some more namespacing quirks that may require one to give up on that sweet syntactic sugar to disambiguate things (two unrelated modules defining methods on a single type, with the same signature but different behaviors, and you need both modules imported for some reason?), but this is, again, something one would have to get used to. It's not a different world like Rust or Prolog.

It's not a complete showstopper, just something I keep bumping my head into now and then.

Re:Nim 2.0 thoughts by michaelsbradley on Saturday May 15, 2021 @11:38AM (#27166165)
> you need to import corresponding modules everywhere

It's a good practice to re-export "all modules whose types appear in public symbols of the current module".

For that and other good advice, see The Status Nim style guide:

https://status-im.github.io/nim-style-guide/03_language.html...

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.
Re:Nim 2.0 thoughts by Aardappel on Sunday May 16, 2021 @01:34PM (#27175386)
If you want a statically typed language with Python-alike syntax but Nim is too "noisy" for you, then Lobster (http://strlen.com/lobster/) is likely spot-on.
Re:Nim 2.0 thoughts by adenozine on Friday May 28, 2021 @11:56AM (#27316952)
You probably won't see this, but in fact I've really enjoyed playing with Lobster!

Thanks for telling me about it, I hadn't taken it seriously before.

Re:Nim 2.0 thoughts by Aardappel on Friday May 28, 2021 @12:56PM (#27317771)
I did see it! Let me know if you have feedback to improve it.
Re:Nim 2.0 thoughts by sp33der89 on Saturday May 15, 2021 @11:08AM (#27165870)
Do you have examples of what you mean with unnecessarily noise? For me it's the JSON operators. `@[]` for sequences could also be a thing, but it's really minor(for me).
Re:Nim 2.0 thoughts by adsharma on Saturday May 15, 2021 @11:16AM (#27165966)
If you prefer python syntax, you can code in python and transpile? Py2many supports nim.

I wonder if there is sufficient interest in having a python stdlib compatible library for nim.

Re:Nim 2.0 thoughts by xigoi on Saturday May 15, 2021 @11:29AM (#27166064)
Re:Nim 2.0 thoughts by adsharma on Saturday May 15, 2021 @12:09PM (#27166442)
Re:Nim 2.0 thoughts by Nimitz14 on Saturday May 15, 2021 @01:01PM (#27166908)
I agree. The syntax is the main reason I don't use it.
Re:Nim 2.0 thoughts by mrweasel on Saturday May 15, 2021 @04:33PM (#27168734)
Completely fair, syntax is something that resonate differently from person to person. I love the idea of Rust, it’s speed, capabilities, it’s politics and it’s independence, but I cannot stand it’s syntax.

That’s fine, I can use other languages and it doesn’t take anything away from Rust or the people who love the syntax.