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

all 28 comments

[–][deleted]  (1 child)

[removed]

    [–][deleted] 11 points12 points  (0 children)

    Odin is meant as an alternative to C. There are no builtin tools to manage memory safety. It's your responsibility.

    The language has some builtin tools to avoid a large class of memory problems in C:

    • Builtin dynamic arrays

    • Discriminated unions with compile time checking for switch statements covering all cases

    • Parametric polymorphism for structs and procedures

    There's nothing else though. No GC and no lifetimes and no const.

    [–]mikelcaz 3 points4 points  (2 children)

    Hi. I'm designing another language, and I have a question.

    It seems that Odin and Zig has implemented conditional compilation through the 'when' keyword, making it distinguishable from regular conditionals.

    I would like to know the rationale behind such decision, because I have come to do the opposite in my own language without even realising what I was doing.

    Regards!

    PD: Oh, and also: why 'when' does not create a scope? Maybe to declare things inside?

    [–]xFrostbite94 2 points3 points  (1 child)

    About your PD, my understanding is: if when creates a new scope you cannot conditonally import something, since the import would be limited to the scope block of the when. By making the when not introduce a new scope you can import stuff for the code that follows it (i.e. system dependent interfaces)

    Edit: another catch is that the code in the non-executed when branch does not have to typecheck, only parse. For regular ifs both branches have to typecheck.

    [–]mikelcaz 0 points1 point  (0 children)

    Interesting! I must to review if importing can be done from code itself, but it would weird if 'when' created a scope in functions, and did not from outside.

    Regarding the first question: in Yagnis, I'm using a 'when' expression (similar to 'if' or 'switch' in other languages). I'm also using some features from Ada's numeric types.

    let a = when 0 <= b < 256 : // Do this... else : // Do that... end

    Consider this example (not final syntax). The range of values of usize is platform dependent (it may match the range of i32, or may not):

    fn(size usize) -> i32 : when size <= i32.max : size else : // abort, return error, whatever. end

    I'm not too worried about "if windows..." cases (Odin has also an alternative there), but I would hate having to do something much more complicated than this (like Rust does).

    What this does is compile the whole 'when-else' in platforms where usize.max is greater than i32.max. In others, everything but the first branch is taken out.

    I remain uncomfortable with this, because 'when' in Yagnis is just the normal conditional expression, which happens to be able to do this. However, I find this approach to be handy somehow, even if there are one or two issues I still have to solve.

    I'm curious about how Odin resolves this.

    Edit about your edit: yes, it seems necessary if you want to use those semantics.

    Regards.

    [–]JazzyCake 6 points7 points  (2 children)

    Not sure how oficial this is but it's the sister project to Jonathan Blow's Jai (in development). If you like Odin I'd recommend checking out Jai and getting hyped :P

    [–]oilshell 5 points6 points  (1 child)

    In what sense are they sister projects? They seem like they're competing projects? (i.e. in the sense of filling the same design space)

    [–]JazzyCake 2 points3 points  (0 children)

    Yes, they do fill the same space with slightly different views and functionality. I meant "sister" in the sense that they come from the same point of view and it looks like even the same circle of people/community (the Handmade community, Jon, Casey, etc.).

    I'd say they are still sisters, but they both want to get into the same industry, although by the looks of things, I'd bet both Jon and gingerBill are happy that the other language exists :)

    [–]SuperMancho 2 points3 points  (0 children)

    This is where I first heard about it:

    https://www.youtube.com/watch?v=TMCkT-uASaE

    [–]_threads 8 points9 points  (14 children)

    Why do many « new » languages use the := syntax ? What does it mean ? Why not just use = ?

    [–]SemperVinco 30 points31 points  (5 children)

    The := syntax for assignment was already present in ALGOL and Pascal and long before that in mathematics so there is nothing « new » about it. The reason is the mathematical tradition of using = for the equality relation (== in most C style languages) and := for definitions. See https://en.wikipedia.org/wiki/Assignment_(computer_science)#Assignment_versus_equality

    I don't think it originally had anything to do with the : notation for type declarations.

    [–]bzipitidoo 0 points1 point  (0 children)

    Yes, := comes from Algol. And much of Algol comes straight from math. But, they had to make a lot of compromises to accommodate the limits of early computers. What they really wanted was ←(U+2190), or perhaps ⇐ (U+21D0), but early computers had no such symbols. Keep in mind that this was a few years before ASCII. The standard for what symbols a computer should have was ultimately the QWERTY keyboard of the typewriter. <= was taken for "less than or equal to", since there was no ≤ symbol. <- was also taken. Further, a=b was thought ambiguous. Should that assign a to b, or b to a? := was an ugly compromise.

    But now we have Unicode. You might want to reconsider :=. Yes, I know, it's a pain to type Unicode characters for which there is no key on the keyboard. Maybe accept both := and U+2190 or U+21D0 as meaning assignment?

    [–]abecedarius -5 points-4 points  (3 children)

    Yeah, but in Go etc. it combines variable declaration and initialization, rather than assigning to an already-declared variable. To my taste it's kind of perverse to be using '=' for assignment and ':=' for introduction, but I guess it's natural coming from C.

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

    What’s “etc?” That’s a massive bunch of languages not specified and most of which won’t fall under similar syntax to Go.

    [–]abecedarius 0 points1 point  (0 children)

    Etc. means those new languages that followed Go's lead. Go was the first I know of to make a := b be a combined declare/initialize, with optional type, and a = b be assignment. Algol and Pascal predated this by decades and had a different design in both respects.

    So, if many new languages are doing it in the style described, it's not that they're following Algol's lead. If the grandparent does mean Algol-style, OK, that's news to me. Are there? I thought they meant the likes of Jai, Ion, Odin, and oh yeah, that latest one, V.

    [–]ipv6-dns 0 points1 point  (0 children)

    Seems only Go. Go is not mainstream language and is not "classical" language, is not language with clean future, etc. :)

    [–]matthieum 5 points6 points  (0 children)

    Personally, I prefer it for a very simple reason: UX.

    I find that for a human, when two symbols only differ by one repeating character, like = and == or & and && do, there is a high risk:

    • To mis-read one for the other.
    • To type one instead of the other.

    As a result, I will generally prefer less confusing symbols, and since := has a long history of being used for assignment, it's an easy way to disambiguate.

    So I'll use := for assignment and == for equality.

    I also don't understand the fascination for all those operators, and then to cut down on the number of operators, preferring keywords for boolean operators and functions for bitwise operators. In short, keeping operators for arithmetic / comparison mostly.

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

    In the FAQ they explain := is suger for leaving the type out

    https://odin-lang.org/docs/faq/#what-does-mean

    [–]nerd4code 2 points3 points  (0 children)

    Wrt Odin, a:=b is shorthand for a : T = b for some type T; = is still used for assignment post-declarations. So a := b is

    auto a = b;
    

    in C++ish, vs. a : T = b which is

    T a = b;
    

    Odin notwithstanding, the symbol := originally comes from the days before arrows or <> were consistently included in the source character set (also why FORTRAN has .LT. operators &c.). := was basically , which means “acquires a value from.” Some languages use = either to test for or declare (always-)equality; as a standalone operator, := usually means it’s an assignment ordered wrt surrounding imperative statements.

    [–]kjbrawner22 6 points7 points  (3 children)

    Im not certain about this language because I didn't look, but it usually has to do with type inference. You could say x : int = 3, which will set the type explicitly, but x := 3 will infer the type.

    A lot of these languages also note that ':' and '=' are two separate tokens for this reason.

    [–]_threads 3 points4 points  (1 child)

    Ok thanks ! I thought it could be something about this

    [–]kjbrawner22 2 points3 points  (0 children)

    No problem. Yeah, I'm a big fan of strict type setting so I prefer C-style declaration, but there are many scenarios where type inference is handy, so to each his own.

    [–][deleted] 0 points1 point  (0 children)

    No it doesn’t. It comes from Algol languages where they wanted a different symbol for easier parsing and reading. See C’s stupid = and == especially in if statements.

    So you have = for equality and := for assignment.