Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
Programming Python

New Release Of Nim Borrows From Python, Rust, Go, and Lisp (fossbytes.com) 199

An anonymous reader writes: "Nim compiles and runs fast, delivers tiny executables on several platforms, and borrows great ideas from numerous other languages," according to InfoWorld. After six years, they write, Nim is finally "making a case as a mix of the best of many worlds: The compilation speed and cross-platform targeting of Go, the safe-by-default behaviors of Rust, the readability and ease of development of Python, and even the metaprogramming facilities of the Lisp family..."

Fossbytes adds that Nim's syntax "might remind you of Python as it uses indented code blocks and similar syntax at some occasions. Just like Rust and Go, it uses strong types and first class functions... Talking about the benchmarks, it's comparable to C. Nim compiler produces C code by default. With the help of different compiler back-ends, one can also get JavaScript, C++, or Objective-C.

There's an improved output system in the newest release, and both its compiler and library are MIT licensed. Share your thoughts and opinions in the comments. Is anybody excited about writing code in Nim?
This discussion has been archived. No new comments can be posted.

New Release Of Nim Borrows From Python, Rust, Go, and Lisp

Comments Filter:
  • I prefer {} instead of tabs/spaces to define my code blocks. It's the only part of Python I don't like.
    • by zalas ( 682627 )

      Do you only use braces or do you indent as well?

      • by Anonymous Coward on Saturday January 21, 2017 @11:12AM (#53710895)

        I use indents, braces and BEGIN and END so....

        BEGIN
        {

        code here

        }
        END

        I'm working on a new version of Anal called Anal++

        Anyways, the language is designed to keep anal retentive developers arguing in nonsense meetings for years to come. "Oh no! Never put the curly braces and the BEGIN/END on the same line!"

        "No, it's better to do so but indent 4 spaces and not a tab!"

        "I STRONGLY disagree, you should never use tabs but SHOULD put the curly braces on the same line!"

        "No no no! Indent AFTER the Begin but before the curly brace!!!!"

        • Which should be solved with an editor which shows the programmer what they want to see, not what others have typed.

    • by caseih ( 160668 ) on Saturday January 21, 2017 @11:05AM (#53710863)

      Interesting how personal preference plays into it. But it also sounds like you haven't spent any real time with Python. Because it doesn't take long to get past the whitespace syntax and get on with programming. For most Python programmers, the block syntax is one of the things they like the most. It's true that a bad copy and paste or accidentally deleting some spaces in the wrong place can break things badly and potentially lead to subtle bugs. But in practice, that doesn't seem to be a significant problem. The fact is you should be indenting consistently anyway, so braces and semicolons are superfluous, and ugly.

      I find I can write several pages of Python code and often it runs the first time without issue, which was never the case with any of the other languages I worked with, including C++. Invariably I'd forget some closing brace somewhere and a semicolon. Compile errors on first run are almost expected with C-like languages.

      Python's real gotchas emerge more from its dynamic nature than its syntax; dynamic typing is a two-edged sword. Test-driven development is pretty much required for large applications.

      Nim of course is statically-typed and has some measure of compile-time safety.

      • It's true that a bad copy and paste or accidentally deleting some spaces in the wrong place can break things badly and potentially lead to subtle bugs.

        Well there's a ringing endorsement if I ever heard one.

        • by caseih ( 160668 )

          Like I said, this is rarely a problem in practice.

      • The problem is when you're tracking down a problem and want to comment out a block of code. With braces it's a simple "if(0){....}'. With whitespace you have to indent the block, which is error prone.
        • How about select the block, then :s/^ /##

        • by caseih ( 160668 )

          You've obviously not used Python before. It's very easy to comment out a block of code and it doesn't require indenting anything, and it doesn't require an if (0) kludge. Your criticism and claim of being error-prone is not valid in this case. Python has a lot of gotchas and warts, but what you describe isn't one of them.

      • The fact is you should be indenting consistently anyway, so braces and semicolons are superfluous, and ugly.

        How is Python's colon any less superfluous? Every block is preceded by a colon, and there is no situation where anything else can go in place of the colon. As far as I can see, the colon is 100% redundant within the syntax. (Excluding list syntax, naturally.)

        • Having tried to code in coffeescript, which has indentation without the colon, I much prefer python.

          • I'm not saying it's a bad thing -- quite the opposite: redundancy is often a good thing. But the justification seems half-hearted, because it doesn't eliminate redundancy, so it's not about eliminating redundancy. It's a block_start token, even if some people choose to play semantics and claim it's part of the command syntax: a block is always preceded by a colon. I don't like the explicit start marker without the explicit end marker. Yes, start marker only does seem a little more like human language, but c
      • by murdocj ( 543661 )

        I really don't like the modern tendency towards dropping syntactic markers like parens or braces. We aren't writing the Torah on lambskin, where every scrap is precious, we have as much space as we want to make the code legible. And if typing the braces is a measurable percentage of the time you spend coding, you aren't thinking enough.

      • by Dadoo ( 899435 )

        Because it doesn't take long to get past the whitespace syntax and get on with programming.

        Agreed. I really don't understand why everyone complains about whitespace, when Python's almost religious insistence on counting from 0 is much more difficult to get used to. I mean, i get why range(8) counts from 0 to 7, but range(1,8) counts from 1 to 7? That makes no sense at all.

      • by AuMatar ( 183847 )

        It isn't personal preferences. Braces are completely superior, using indentation alone causes problems:

        *Mixing of the two causes programs to perform differently, but the bug isn't visible. This once cost me 3 weeks to track down a bug where one line in 30K from a contractor used a tab instead of spaces. This isn't the only time I've seen it cause bugs, just the worse.

        *Copy pasting from the web is nearly impossible.

        *When editing other people's code you don't know what to use. I actually just copy paste t

      • > The fact is you should be indenting consistently anyway, so braces and semicolons are superfluous, and ugly.

        Why do python advocates always assume you have the luxury of exclusively working with your own code?

      • it doesn't take long to get past the whitespace syntax and get on with programming

        You might get past it, but it will never stop bothering you. One of the more spectacular blunders in language design, imho. Another one, also in the Python camp, is the brain-damaged aversion to efficient executables. It says a lot about the language that it succeeds in spite of those two remarkable displays of incompetence. But Perl, not to be undone, came up with "there's more than one way to confuse things".

    • That and the language (lack of) compatibility.

      I wrote a project in 2.6 a while ago but a week before production I'm told that the machine would use 2.4
      Imagine my surprise when I noticed that some keywords were working differently (something about the exception handling was looking like it was working, but breaking, I don't remember exactly what).

      Now, if I want to use some scripting language to quickly so something (by opposition to do something fast) I use perl (cleanly) or bash.

      (For the serious stuff I'm m

    • I prefer {} instead of tabs/spaces to define my code blocks. It's the only part of Python I don't like.

      Same here. I confess I like the "syntactical sugar" of curly braces. I think it improves readability by an order of magnitude. The whole deal with using whitespace as code block delimiters seems retarded to me.

  • by alvieboy ( 61292 ) on Saturday January 21, 2017 @11:01AM (#53710847) Homepage

    Nim (*).

    We are The Knights Who Say "Ni!".

    (*) In Portuguese, "Nim" can be seen as a hybrid of "no" [Não], and "yes" [Sim]. Often used to express "I could, but I won't".

  • The example code I've seen from Nim reminds me a bit of Pascal. At least the use of the keywords proc and var. Glad they went with Python-style blocks instead of Pascal-style begin and end.

    But nim does look like a nice language. The fact that it generates C code and compiles with a C compiler means that it could be integrated quite smoothly into projects using other languages.

    Nim is on my list of languages to try some time if I ever need to write C-compatible code.

  • "...the readability and ease of development of Python..."

    I'll admit I'm not really a Python user, but I've seen lots of Python code and compared to other languages I've never considered Python to be very readable.

    • by HiThere ( 15173 )

      The language that's easy to read is the one you know well. I've used Python enough to think that it's easier to read than C or often C++ code that does the same thing. C's problems is indirections via multiple levels of pointers and macros. With C++ it is just that the language as a whole is too large, and I only know parts of it well, though it can include C's problems as well (but it doesn't need to).

      • The language that's easy to read is the one you know well.

        That may be, but I admit I find syntactic sugar like braces and semicolons help me significantly in visualizing the code blocks, functions, etc.

  • HAI 1.2
    CAN HAS STDIO?
    VISIBLE "I've been looking for something to outdo LOLCODE in terms of pointlessness. ;)"
    KTHXBYE

  • Just reading the docs, the first thing that pops out at me is that there is no need for a separate 'const' and 'let' keyword. They describe the difference as:

    "The difference between let and const is: let introduces a variable that can not be re-assigned, const means "enforce compile time evaluation and put it into a data section":"

    But the compiler can detect whether the expression on the right hand side of the let assignment is compile time constant, and "put it in the data section" if it is; no need for t

    • Another critique: the 'discard' keyword is unnecessary. "Forgetting to use a return value" is not a bug vector in my experience. No reason to force the programmer to tell the compiler "yeah I really didn't mean to use the return value of the function I called".

      • Re: (Score:3, Insightful)

        by Bryan Ischo ( 893 ) *

        Here's a big one: overloaded operators are terribad.

        "The Nim library makes heavy use of overloading - one reason for this is that each operator like + is a just an overloaded proc. The parser lets you use operators in infix notation (a + b) or prefix notation (+ a). An infix operator always receives two arguments, a prefix operator always one. Postfix operators are not possible, because this would be ambiguous: does a @ @ b mean (a) @ (@b) or (a@) @ (b)? It always means (a) @ (@b), because there are no post

        • Here's another unnecessary weakness:

          "Parameters are constant in the procedure body. By default, their value cannot be changed because this allows the compiler to implement parameter passing in the most efficient way. If a mutable variable is needed inside the procedure, it has to be declared with var in the procedure body. Shadowing the parameter name is possible, and actually an idiom:"

          Re-using parameters as variables is very useful for writing concise code. I see no reason to limit things in this way. I

        • Someone modded my comment as "Troll". I cannot even fathom what would lead someone to do that. My comment was a critique on the language. WTF is trolling about discussing the characteristics of a programming language in a discussion forum about that programming language?

        • Sorry, I can't disagree with you more about this.

          As a videogame programmer, a significant amount of what I do is working with user-defined types like geometric vectors, matrices, quaternions, etc, all of which have well-defined operations that use mathematical notation, and it makes a big difference when I can write code in a natural and intuitive style. Just because someone could theoretically abuse a feature doesn't mean it's still not a useful feature. You could completely misname a function that adds

          • Well I guess we've had different experiences then.

            matrix.multiply(other) doesn't seem that much worse to me than matrix * other, and in my opinion is more self-documenting since I know that a function is being invoked. And have you tried to actually write coherent operator overloading for any class? My god it's ridiculous in C++; the syntax for doing so is awful and the number of niggly details you have to get right or leave yourself open to weird bugs that will only show up much later when someone else t

            • "so why does Nim need a feature only useful in video game inner loops"

              yeah that is a bit of a straw man, I admit. We never established that operator overloading is a feature only useful in video game inner loops.

              But I will say that I think it's generally only useful in a narrow and small subset of programming problems: those for which mathematical constructs already exist and for which math operators are meaningful. Most people don't write code using quaternions and matrices. General control logic and da

        • That old story again. You know what the + operator does? It adds two things together. How it does that is really none of your business.

          You probably think that you know what happens when you write x + y. Well, you don't. It all depends on the type: if x and y are integer, an integer addition instruction is used. If they are floating point a floating point addition instruction is used. And if one is integer and the other floating point there is first a conversion, and then a floating point addition. If one is

          • The ways that + can behave in C can be enumerated without knowing anything else about the program. But overloaded operators in C++ cannot be enumerated without knowing the types involved and doing an inspection on those types to see if the operator is overloaded.

            It's a trade-off. Sure operator overloading allows some concise representations. But it's information hiding. That's not a trade-off that I think is wise to make. Other people obviously differ in their opinion.

        • by HiThere ( 15173 )

          I've got to disagree...though not totally. ISTM that overloaded operators need to be marked, rather than eliminated. I once suggested that overloaded operators be enclosed in pipe chars, e.g. |+|, but nearly any mark would do. And this be only used for operators. I also wanted to allow alternative symbols, names, etc. to be used for operators, but there I ran into the precedence problem

        • by serviscope_minor ( 664417 ) on Saturday January 21, 2017 @07:12PM (#53712975) Journal

          I strongly disagree.

          The first mistake is not knowing C++ well. a+b means operator+(a,b). It's a function call with a funny syntax. No more, no less. Now we're on to function calls, nothing in your language stops someone from writing a function called add() which does something silly. Or sensible.

          Why is it worse having a+b than add(a, b) when a and b are complex as per your example?

          • a + b for complex types isn't really the trouble, since we know that the compiler can only accept that syntax if the + operator has been overloaded.

            What's worse is overloading [] or -> and competely fooling the programmer who has no way of knowing, without exhaustively scanning all source files, whether or not those operators are doing something unusual.

            Information hiding. It's bad.

            • Nope that's no different.

              a[b] means index(a, b). Information is no more hidden than if you have to look for index() versus looking for operator[]. Operators are not magic, they're just functions with an alternative syntax. If you have a problem where programmers are fooled because someone keeps committing an index() function to the repo which does something else entirely, the problem isn't overloading, it's that you're not doing code reviews properly.

        • If you actually write code that does lots of math on vectors and matrices and so-forth, you might change your opinion. Added to which, the oft-trotted-out argument that '+' might be doing something other than adding due to overloading is moot, since the same can be said of a function called 'Add'.

  • by ooloorie ( 4394035 ) on Saturday January 21, 2017 @12:16PM (#53711197)

    Nim sounds similar in its goals to D [wikipedia.org], another batch-compiled statically typed language with GC. The main difference is that Nim seems to innovate a lot syntactically. How do the languages compare otherwise?

  • by kwerle ( 39371 ) <kurt@CircleW.org> on Saturday January 21, 2017 @12:48PM (#53711371) Homepage Journal

    Looks like another language that does not thoroughly address parallel processing. With the mention of go, I was hoping for something like goroutines (one of the few things I like about the language) - but no. Doesn't look like it.

  • I found programming in nim fun; when I looked into runtime debugging nim, I wasn't very convinced I could actually use it for anything anytime soon.

  • Yet another language. What Nim is good for?

If you steal from one author it's plagiarism; if you steal from many it's research. -- Wilson Mizner

Working...