Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wouldn't this be better served with defaults?

    // constructor
    func init (a, b, c) {
        if (!a) a = 0;
        if (!b) b = 0;
        if (!c) c = 0;
        x = a; y = b; z = c;
    }
Like

    func init (a=0, b=0, c=0) {
        x = a; y = b; z = c;
    }


Yes, but I guess it's only an example to demonstrate one liners and anything would do. I prefer not to have to surround conditions with () and terminate statements with semicolons. Plenty of languages demonstrated that it's ok. However I don't know how that impacts the complexity of the compiler. I used to know how to write one and reason about it but I spent my last 25 years doing other things.

Nice touch to be able to do

    func + (v) { ... }


In Lua, this would be:

    function init(a,b,c)
      local x = a or 0
      local y = b or 0
      local z = c or 0
    end
"and" and "or" short circuit evaluation in Lua; nil and false are false, everything else (including 0) is considered true.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: