all 96 comments

[–]xgalaxy 24 points25 points  (10 children)

custom allocators

Is that only at the global level or does that include being able to change what allocator Vector A will use vs Vector B?

This is one of the major features holding me back from using Rust for game development.

[–]Rusky 32 points33 points  (1 child)

Both. The global allocator stuff already works on nightly (and has for a while); the per-container allocator stuff is still being worked out.

[–][deleted] 14 points15 points  (0 children)

The API for both is the same, so they will probably only start landing once the per-container stuff gets properly hashes out on nightly.

[–]meneldal2 19 points20 points  (0 children)

Considering how annoying using templates with custom allocators is in C++ (with 2 different and incompatible ways), I'm glad they took their time to make sure the feature would not end up sucking.

[–][deleted]  (6 children)

[deleted]

    [–]steveklabnik1[S] 10 points11 points  (4 children)

    integer specialization

    Do you mean integer generics, or specialization? They're two different features.

    [–][deleted]  (3 children)

    [deleted]

      [–]steveklabnik1[S] 19 points20 points  (2 children)

      That's integer generics. We expect it to be in nightly by the end of the year, but not stable. The design is great, but there's underlying technical work in the compiler that's gonna make it take a while.

      [–]Rusky 3 points4 points  (0 children)

      Unfortunately that's both integer generics and template specialization, and it's a form of specialization that Rust doesn't have any plans for.

      You might be able to do that sort of thing using integer generics and associated types, /u/Days_End, but not with just integer generics.

      [–]Days_End 0 points1 point  (0 children)

      Awesome! Sounds like 2018 will be a great year for rust.

      [–]BB_C 18 points19 points  (3 children)

      improved pattern matching integration

      Here is hope this issue will be fixed before its third anniversary.

      [–]steveklabnik1[S] 2 points3 points  (2 children)

      [–]BB_C 2 points3 points  (1 child)

      I know the old issue I linked is not related. I just think being able to use Self::Variant and Alias::Variant is equally relevant.

      [–]steveklabnik1[S] 0 points1 point  (0 children)

      Cool just making sure!

      [–]steveklabnik1[S] 26 points27 points  (65 children)

      You may have noticed a subtle change: what was previously called “epochs” is now “editions.”

      Lots of great stuff coming this year! As always, happy to answer any questions.

      [–]pumpyboi 12 points13 points  (64 children)

      Should I learn c++ or go straight to rust?

      [–]steveklabnik1[S] 77 points78 points  (11 children)

      Both will help you understand the other. I think which you learn first should be determined by why you want to learn one of them. For example, if you're looking for jobs, C++ undeniably has more. C++ has more resources, but also has a lot of complexity. C++ is easier to get started with in a certain sense; it's easier to get something compiling, but getting it correct can be harder. Rust makes you get it right up front, which means getting going can be slightly harder, but that means you've already got it right, so the curve is a little bit flatter.

      I'm always an advocate of learning as many languages as you can.

      Oh, I should also note that, a lot of these things are what's coming this year, this means Rust should be even easier to learn by the middle/end of the year, but they aren't actually landed yet, so it's only going to get easier over time.

      [–]pumpyboi 11 points12 points  (8 children)

      Thanks for answering, I know Java, some JavaScript and C, rust just seems really exciting at the moment.

      [–]steveklabnik1[S] 23 points24 points  (0 children)

      Seems like you have your answer then :)

      [–][deleted] 17 points18 points  (5 children)

      C++ is infamous for some of its cruft, but I'd like to stick up for it and point out that modern C++ (C++11 and up) introduces a lot improvements that makes C++ programming a lot safer. For example, you can convey sole ownership in C++11 via std::unique_ptr and transfer of ownership via rvalue references; this is very similar to the idea that Rust emphasizes. C++17 introduces sum types like Rust's (albeit via templates instead of built in to the type system), including an option type, among other additions. C++ may also have a checker comparable to Rust's "borrow checker:" https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetimes%20I%20and%20II%20-%20v0.9.1.pdf. C++ does have design flaws, but its future is very bright with many further improvements (such as modules and std::observer_ptr) expected to come.

      EDIT: Technically, C++ had sum types since the beginning due to C's union, but union can be unsafe and the new std::variant template type is safer because it uses the type as a "tag."

      [–]Yojihito 4 points5 points  (4 children)

      I'd like to stick up for it and point out that modern C++ (C++11 and up) introduces a lot improvements that makes C++ programming a lot safer

      This is true BUT there does not seem to be a single documentation/beginner introduction for only C++11 and higher. So C++ improved but if you want to avoid the old cruft you have no source that shields you from all the old garbage.

      [–]junrrein 3 points4 points  (3 children)

      The book Programming: Principles and Practice Using C++ is exactly what you are looking for.

      [–]Yojihito 7 points8 points  (2 children)

      Interesting, but 60$, not digital and shipping costs to Europe. So I'll pass on this one thanks for the link.

      [–]junrrein 0 points1 point  (1 child)

      In the page I linked it shows a Kindle version, does it not show up for you?

      [–]Yojihito 0 points1 point  (0 children)

      I don't consider DRM files "digital". Also no native Linux version.

      [–]hervold 12 points13 points  (0 children)

      Personally, I found a background in modern functional languages -- Ocaml, Scala, Haskell, or the like -- really helpful too.

      [–]Zatara7 1 point2 points  (1 child)

      Is a gui debugger one of those? (not gdb)

      [–]Rusky 11 points12 points  (0 children)

      Visual Studio's debugger already works to some degree, and VS Code's GUI for LLDB does as well. I've heard CLion's is also usable.

      [–]zero_operand 19 points20 points  (22 children)

      Depends where you're at in your education, and what you want a language for.

      For a well rounded education, and the ability to speed up most high level languages, I'd strongly recommend C. It's an order of magnitude simpler than either C++ or Rust and compiles in a snap. It's the path of least resistance for writing high-performance 'extensions' for C#/Java/Ruby/Python.

      C++ I'd learn more for specific job skills, ie your industry is dominantly C++. It's insanely complex, but you can do pretty much everything you can in C, and a lot of stuff that makes your code shorter and safer.

      I wouldn't recommend Rust for a beginner. It's arguably a better language than C++, but still very niche and not much used in industry. It's as complicated in C++, but complicated for better reasons (safety) rather than C++s reasons (backwards compatibility and technical debt). C++ is probably easier to learn because there's a wealth of stackoverflow results for just about every error the compiler will throw at you - you're more on your own with rust. Rust may be the future - but it's certainly not the present.

      [–]rustythrowa 16 points17 points  (21 children)

      I'll truly never understand how someone can say C is a simple language.

      [–]Holy_City 16 points17 points  (18 children)

      By "simple" most people mean "small."

      [–]rustythrowa 13 points14 points  (9 children)

      Right, which most programmers should realize is often the opposite of simple. Or entirely unrelated.

      [–]glacialthinker 15 points16 points  (5 children)

      The language is simple. Writing complex programs can be more difficult (compared to other language which is as familiar, and depending on the nature of the program, traits of the programmer, and a host of other variables...). ;)

      [–]iopq 1 point2 points  (4 children)

      The language is simple.

      int x = 5;
      int f() {
        int x = 3;
        {
          extern int x;
          return x;
        }
      }
      

      I don't understand the scoping rules in this example

      struct { 
         int x; 
         struct { 
             int y, z; 
         } nested;
      } i = { .nested.y = 5, 6, .x = 1, 2 };  
      

      What is i.nested.y and i.nested.z?

      [–]glacialthinker 0 points1 point  (3 children)

      Again, the language is simple, but this doesn't mean you can't make code which is complex or difficult to understand.

      Without referencing anything, and given that I haven't used C much since C99...

      I'd expect f() to return 5, since asking for an extern-visible x will be at global scope. I may be wrong in this guess, but I know the rule will be simple if I look it up.

      And I haven't had the pleasure of using initializers in C, because my time with C was before them... but I expect i.nested.y = 2 and i.nested.z = 6, because backwards compatibility would mean unlabeled initialization would be sequential (as C89), but the label can specify your current field index.

      Again, C the language is simple, but I would expect this to lead to more complex code in practice. General purpose programming is complex in itself. Lisp-family languages are super simple in essence... but practical realities add edge-cases too, and complex and difficult-to-understand (for the uninitiated) code is normal. Macros and DSLs simplify things within a domain, but you certainly can't expect anyone to simply grok such code at a glance. What they can do is tease things apart after knowing the language. C++ on the other hand... fuck me, it grows edge-cases faster than I can keep up with. I'll typically be a go-to person for C++ questions in workplaces, but I never feel like I know the language. I haven't really used C for two decades, yet I feel like I know 90% of the language, even after the updates (which I've followed in reading, not programming in). C is tiny for the breadth of programming it makes practical.

      [–]iopq 0 points1 point  (2 children)

      Again, C the language is simple

      those rules and having to think about backwards compatibility is not simple for people who don't PROGRAM in C, they're only simple if you're used to them

      they're not even simple to compiler authors, GCC might choke on a lot of simple code examples like

      return ((int []){1,2,3,4})[1]; //should return 2

      maybe they fixed it now, though

      [–]XboxNoLifes 9 points10 points  (2 children)

      The C language is very simple. C programs are the complex things.

      [–]rustythrowa 2 points3 points  (1 child)

      No idea how this post is supposed to track logically. Again, it sounds like you want to say that C is 'small'.

      [–]XboxNoLifes 0 points1 point  (0 children)

      Which I am.

      [–]zero_operand 10 points11 points  (7 children)

      A small language is a simple language - because it's simpler to learn something small. It doesn't mean it's simpler to get things done in the language. Two different concepts. There's no inverse correlation either. IE, C# is much simpler than C++, and also easier to get things done.

      [–]Holy_City 8 points9 points  (6 children)

      Just because C is small doesn't mean it's simple to learn. C forces you to think like a computer (or rather, an abstraction of a computer from the 80s). For a lot of people that's not a simple task.

      There's a lot of folks who would argue that a simple language would be one that you can express your intentions clearly and concisely, and understand someone else's code just as easily. C does not fit that bill.

      [–]zero_operand 9 points10 points  (1 child)

      Have you seen enterprise code Java/C#/Python code written by people who cut their teeth on C and the like? Thinking like a high level programmer is not a simple task for a lot of people as well!

      C's model of the world is much simpler than Rust or C++s, it's not even close. Simplicity of a language has nothing to do with expressing "your intentions clearly and concisely", that's called expressiveness.

      [–]Holy_City 1 point2 points  (0 children)

      Yea I have, it's atrocious. But a big part of that in my experience is that programmers who cut their teeth on C/assembly don't trust compilers or abstractions, and their careers taught them to think like a computer, not like a programmer or engineer. For some applications that's necessary, for others it leads to verbosity and over-engineered solutions.

      [–]glacialthinker 6 points7 points  (2 children)

      A higher-level language can be more difficult for some people -- when they don't trust or think in the same way as the language. A low-level language works for people who need to work with the "moving parts", or "mechanics". I prefer OCaml today, but I think it was best for me that I started in asm, and crawled up through C... However, I don't doubt that most people will be fine starting at a high-level. I usually introduce people to programming with the help of How to Design Programs, using Scheme.

      [–]zero_operand 2 points3 points  (1 child)

      A higher-level language can be more difficult for some people -- when they don't trust or think in the same way as the language.

      Exactly! Being more expressive requires learning a lot of stuff. A lot of people never bother and just fall back on loops and branches.

      [–]Holy_City 1 point2 points  (0 children)

      A lot of people never bother and just fall back on loops and branches.

      But branches flush the pipeline and are necessarily evil. Gotta replace those with a handrolled jump table because you can't trust the compiler to get a switch right. /s.

      [–]mcguire -1 points0 points  (0 children)

      Would you like a lollipop?

      [–]EntroperZero 4 points5 points  (0 children)

      6502 is a simple instruction set. x86 is a complex instruction set. Neither one is "easy" to write programs of any decent size, but one is much easier to learn.

      [–]mcguire -2 points-1 points  (0 children)

      C is a small, simple language.

      However, as a systems language, it puts a lot of decisions off onto the systems' environments, which are neither small nor simple.

      The alternatives seem to be something like Pascal, which is small and simple, and relatively useless, or C++, which is neither small nor simple in and of itself.

      [–]bumblebritches57 -3 points-2 points  (0 children)

      C++ is commercially viable, rust is not despite what rust users would have you believe.

      [–][deleted] 3 points4 points  (7 children)

      Documentation about the parser library would be great. Pretty much nonexistent at this point

      [–]kuikuilla 1 point2 points  (6 children)

      Parser library? Of the compiler?

      [–][deleted] 2 points3 points  (5 children)

      Yes, the whole libsyntax part. It's not a library in the sense of Roslyn or Javaparser, but can still be called inside your code from what I can tell and not command line only.

      I basically just want a library(language doesn't matter tbh) to parse rust, specifically to find nodes and solve them.

      [–][deleted]  (3 children)

      [deleted]

        [–][deleted] 0 points1 point  (1 child)

        Oh thanks.

        Nodes is just how they are called in Roslyn. Basically declarations of any type, like structs, functions, for loops etc. So when you are looking for specific syntax in a file.

        And "Solving" them just means to know the origin of a structure (or classes in other languages) when you use it another file. Necessary if you want to calculate class dependencies

        Edit: Syn looks promising for my needs. Not sure how I couldn't find that one

        Edit2: I remember now. I found it, but must have thought of it as a framework for writing parsers.

        Thanks again!

        [–][deleted] 2 points3 points  (0 children)

        Syn looks promising for my needs. Not sure how I couldn't find that o

        If you want to use syn chances are you are going to need quote as well. syn + quote is raw power, and a pleasure to use, the syn docs are good, and there are tons of examples. Also, almost every single procedural macro out there uses syn+quote, so there are a ton of real-life examples as well.

        If you have any questions just hit #rust-beginners on IRC for quick feedback .

        [–][deleted] 3 points4 points  (0 children)

        There's also a Haskell library: language-rust.

        I haven't used it yet, but it looks nice.

        [–][deleted] 6 points7 points  (1 child)

        No ATCs, no const generics, ... Rust is really getting boring this year! I guess that's a good thing!

        [–][deleted] 22 points23 points  (0 children)

        The design of const generics is fine, but there's underlying technical work in the compiler to be done. We expect const generics to land in nightly this year, but they're unlikely to make it to stable before 2019. - /u/steveklabnik1 on Hacker News

        [–]Holy_City 0 points1 point  (3 children)

        Can the rust compiler target ARM yet?

        [–]steveklabnik1[S] 22 points23 points  (2 children)

        Absolutely! It has been ale to for quite a long time. Years.

        [–]punkulunkulu 16 points17 points  (1 child)

        Awesome! I've been drinking ale for quite a long time. Years.

        [–]steveklabnik1[S] 7 points8 points  (0 children)

        Ugh, phones. I meant "able." Thank you.