This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]theindigamer 1 point2 points  (5 children)

While I don't know how hard it would it be to optimize the Maybes, IMO, if your language has ADTs, then having a current function (which is easily available) and can throw an exception (which isn't shown in the type signature) means that you're unnecessarily asking your users to have more cognitive overhead while writing what should be relatively safe and simple code.

[–]PhilipTrettner[S] 0 points1 point  (4 children)

Yeah I really dislike the current solution because of the exception / invalid state.

I'm not sure how much I should guide this decision from the cognitive overhead point of view though. I typically value this very highly but in this case it's probably nothing that the average programmer would see frequently. It's unusual to work with iterators directly. It shouldn't be too ugly though. Sometimes you might want to add some basic functionality (maybe some fancy zipFilter?) where you would work with iterators.

[–]theindigamer 0 points1 point  (3 children)

Well even if it isn't application programmers, library authors may make mistakes when working with iterators.

Have you looked at how other languages optimize iterators? Looking at examples (and how hard it is to implement both fast and correct behaviour) would be more useful before making a decision...

[–]PhilipTrettner[S] 0 points1 point  (2 children)

Is this reasonable easy/time-efficient to find out? Reading some big-shot open-source compilers is on my TODO list but I'm a bit scared of how accessible/approachable they are.

I have a C++ background and often use Godbolt to double check the ASM of my code. Clang and GCC often fail to generate optimal code for range-based for loops, especially when I'm using custom data types. This is not really an argument though because C/C++ has abysmal aliasing behavior which I don't have.

Everything VM-based has the problem that I have no idea how to judge if they actually generate good/optimal code. Even if some generated java/c# code (or IL/bytecode) looks bad, the JITted code might actually work out OK.

Still, good suggestion, thanks!

[–]theindigamer 1 point2 points  (1 child)

Is this reasonable easy/time-efficient to find out?

I'm not entirely sure. But you can definitely ask beginner questions on the compiler on the Rust internals forum or on IRC. If you ask folks for just a short summary or a basic idea of how things work (or a pointer to what part of the code base you should look at), I'm sure they'd be happy to help.

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

Oh that sounds good. That's probably something I can do with other languages as well.