Live data from Hacker News

I like Odin

hasenjudy.wordpress.com

161–170 of 211 posts

Re: I like Odin

#161
post #98

I think Odin just doesn't do enough. The improvements over C are there, but imho too small to justify/motivate a large-scale change. And personally I think (!) there is no reason to introduce a new programming language without RAII these days. If you don't solve memory management any more than C did (not), then you are ignoring the biggest problem that needs solving and every replacement that does address this proble…

And for you, you clearly don't need manual memory management nor high control over memory, memory layout, and memory access. And that's absolutely fine, but don't criticize something which other people REQUIRE and DESIRE. You cannot "solve memory management" because there isn't just "one problem". As for RAII, the article itself showcases some of the alternatives Odin has with the `defer` statement and `deferred_*` a…

My point was that I don't see much of a point in yet another language that is C with an extra 10%. There is another one like that almost every week.

Plenty of applications that require manual memory management have been written in C++ or Rust, which do provide RAII. If you know that manual memory management is required for some applications, you also know it's not 100% of the code that needs it.

Re: I like Odin

#162
post #128

Earlier quoted context omitted.

That’s fair. That’s however not what the OP claimed, which is what I was responding to.

The creator of Odin has made it very clear he was inspired by and borrowed from both Go and Jai, which is perfectly acceptable. It's also very obvious, to any who have looked at the documentation or used the languages. The other poster already gave you a link, where Go is acknowledged. If you investigate further (Google), you will see that Jai inspired and was borrowed from too. I suppose your argument is about Odin,…

[deleted]

Re: I like Odin

#163
post #98

I think Odin just doesn't do enough. The improvements over C are there, but imho too small to justify/motivate a large-scale change. And personally I think (!) there is no reason to introduce a new programming language without RAII these days. If you don't solve memory management any more than C did (not), then you are ignoring the biggest problem that needs solving and every replacement that does address this proble…

I agree RAII at a minimum should be available, but why not just use c++ at that point? I'll just go to something like zig or rust that is established and has thousands of libraries available.

I recommend reading my reply to another comment regarding RAII: https://news.ycombinator.com/item?id=32629951

Also the article itself demonstrates different approaches to achieve behaviour similar to RAII through the `defer` statement and `deferred_*` attributes.

Re: I like Odin

#164
post #157

Earlier quoted context omitted.

You are correct and Odin supports all of this. `Maybe(^T)` exists in Odin. Bounds checking is on by default for all array-like access. Odin has fixed-length arrays, slices, dynamic arrays, maps, and #soa arrays, all of which support bounds checking. Odin does not have pointer arithmetic nor implicit array-to-pointer demotion which is pretty much removes most of the unsafety that languages like C have. Odin also has b…

Odin and Zig solve almost all the memory safety aspects, except for use after free. Having bound checks, union types, etc. is good and a real improvement over C, but I think that use after free is a memory unsafety issue. It's the one that's harder to tackle because it's more dynamic ("temporal memory safety"?).

"Use after free" is a symptom of other problems. You can "solve" it by making it very different to do in the first place with something ownership semantics, but there are usually better ways of dealing with it in the first place.

One really good approach is to not use pointers in the first place and use handles. I highly recommend this post for more information: https://floooh.github.io/2018/06/17/handles-vs-pointers.html

Because use-after-free is a responsibility problem, handles are a way to make sure that a subsystem has responsibility over that memory directly rather than have it spread out across the program.

This is why Odin nor Zig "solve" this problem: solving it at the language level is not necessarily the best option.

Re: I like Odin

#165

Earlier quoted context omitted.

Quite the outlashing. One can use both default RAII in a programming language as well as opt-in unsafe memory management. So you are clearly wrong in your assumptions about what the OP must clearly not require/want.

Still no. Many problems require manual memory management of which custom allocators aid a lot with. Odin has extensive support for custom allocators and many other things. RAII may not even make sense within the type system of a language too. Languages with RAII (C++, D, Ada, Rust (through Drop), and Vala) all have higher level constructs such as methods, and many have automatic memory management too (Rust's is autom…

I want to address some points for people that are reading and don't have enough C++ experience to judge that they are not as serious as they might seem.

* You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done.

* Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed.

* I read and write C++ every day at work and in my free time and I rarely find this to be a problem. If I see a non-trivial type, I assume it's destructor is called at the end of scope. And whether I have to look up the destructor of some type or a corresponding free function (like in C code usually), makes no difference to me.

* Gamedev can live entirely without exceptions and many other software projects do as well. You just have to write your constructors so that they do little work (which is encouraged anyways) and use methods to initialize them. Having static methods that return an optional is also pretty common.

Of course you can also have constructors that do a ton of work, so you never know what is being done, exception handling everywhere to error handle all that code and not use move semantics or very old C++ versions. There are always ways to use a language in a bad way and get bad results. I am sure you have seen bad C code.

Of course RAII is not simple. It's extremely complicated, which is why I consider it missing. Using a new language needs be justifyable by some significant added value.

Re: I like Odin

#166
post #143

Earlier quoted context omitted.

Rust sounds like what you want, though be prepared to deal with near C++ levels of complexity at times (lots of Rust code is too macro happy for my tastes). That said, the way to deal with memory management in C is to... not do much of it. I know that sounds like a cop-out but the patterns you're supposed to use in languages like Zig and Odin are the same ones you'd use in C to keep your mind sane. Do not do Referenc…

I’ll admit, the fact that Hello World requires a macro, dissuaded me from learning Rust for years.

You’re using the past tense. Did your mind change?

Re: I like Odin

#167
post #165

Earlier quoted context omitted.

Still no. Many problems require manual memory management of which custom allocators aid a lot with. Odin has extensive support for custom allocators and many other things. RAII may not even make sense within the type system of a language too. Languages with RAII (C++, D, Ada, Rust (through Drop), and Vala) all have higher level constructs such as methods, and many have automatic memory management too (Rust's is autom…

I want to address some points for people that are reading and don't have enough C++ experience to judge that they are not as serious as they might seem. * You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done. * Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed. * I read and write…

I absolutely agree, I've written a few hundred thousand loc of C++ at this point and I don't remember one time where I felt that having RAII was anything but great. It made me absolutely hate whenever I had to work in other languages Java and C# and had to remember to release non-memory resources manually.

Re: I like Odin

#168
post #165

Earlier quoted context omitted.

Still no. Many problems require manual memory management of which custom allocators aid a lot with. Odin has extensive support for custom allocators and many other things. RAII may not even make sense within the type system of a language too. Languages with RAII (C++, D, Ada, Rust (through Drop), and Vala) all have higher level constructs such as methods, and many have automatic memory management too (Rust's is autom…

I want to address some points for people that are reading and don't have enough C++ experience to judge that they are not as serious as they might seem. * You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done. * Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed. * I read and write…

> You can just have your constructors not initialize your member variables. If they don't have default constructors that do work, then no work is done.

So your constructors don't do any construction?---defeating the entire point of a constructor.

> Yes, originally. Move-semantics are part of the language since C++11. Enough time has passed.

First, move-semantics solve a lot of the issues with copy-constructors in C++, as I previously stated. Secondly, what has time got to do with this? It's a solution in C++'s RAII with copy-constructors. Not the only possible solution but the one that the C++ committee settled on.

> I read and write C++ every day at work and in my free time and I rarely find this to be a problem. If I see a non-trivial type, I assume it's destructor is called at the end of scope. And whether I have to look up the destructor of some type or a corresponding free function (like in C code usually), makes no difference to me.

I'm also assuming that your code base uses constructors and destructors all over the place and is absolutely fine with the added costs of constructors and destructors. And that's fine. But they are implicit and when reading the code, you don't necessarily know if a constructor is being called from just reading it. That is just a statement of fact and not really a criticism.

> Gamedev can live entirely without exceptions and many other software projects do as well. You just have to write your constructors so that they do little work (which is encouraged anyways) and use methods to initialize them. Having static methods that return an optional is also pretty common.

Firstly, is the argument here to make constructors only do trivial things in?---(which rarely ever happens in practice, especially if you use anything from the STL). Secondly, many game devs usually have have an explicit `init` method too for the exact reason you can separate allocation and initialization, and have the ability to handle failure cases with `init`, usually with a return value indicating this failure state. You can have static methods, yes, but then you are literally getting around the construct of an implicit constructor and having an EXPLICIT construction call.

RAII itself is actually very simple, but to make it useful is complicated and complex. The issue with RAII is not necessarily the scope-exit semantics but rather coupling this within the type system itself as a way to have scope-hierarchical-based management of resources.

Re: I like Odin

#170

Reading through Odin (very neat overall!) I am a bit confused on the additional boolean types. "bool" seems to be your standard boolean but then there are b8, b16, b32, and b64. Bitfields seem to be their own thing still so are these just boolean types with a wider backing for something like a data format that stores them that way?

There are a few reasons as to why there are different sized booleans in Odin. One is dealing with foreign code. A lot of old C code used their own boolean type before it was standardized. And many people defaulted to typedeffing `int`. A good example of this is Win32's `BOOL` which is `int` sized, which would be backed by `b32` in Odin. Another reason is that file formats may use different width booleans to a single…

Thanks, appreciate the detailed answer!
Post reply on HN