8 votes

Fortnightly Programming Q&A Thread

General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.

Don't forget to format your code using the triple backticks or tildes:

Here is my schema:

```sql
CREATE TABLE article_to_warehouse (
  article_id   INTEGER
, warehouse_id INTEGER
)
;
```

How do I add a `UNIQUE` constraint?

9 comments

  1. [8]
    lonjil
    Link
    Anyone here try/use Zig? I don't program on that low a level often these days, but when I do I've usually used C. Now, Zig is really feeling like a proper C replacement for me, unlike other recent...

    Anyone here try/use Zig? I don't program on that low a level often these days, but when I do I've usually used C. Now, Zig is really feeling like a proper C replacement for me, unlike other recent attempts.

    What do y'all think?

    5 votes
    1. [6]
      Moonchild
      (edited )
      Link Parent
      To me, a large part of what's meaningful about c is its ubiquity. There are compilers for it everywhere. Toolchains for other natively compiled languages depend on the c toolchain and runtime, so...

      To me, a large part of what's meaningful about c is its ubiquity. There are compilers for it everywhere.

      Toolchains for other natively compiled languages depend on the c toolchain and runtime, so you never really end up in a situation where someone has a toolchain for another language but not for c. (Notable recent exceptions include zig and go—but zig still comes with a c runtime even though it runs without one.)

      If you don't need that ubiquity, then sticking with c-like languages for low-level programming is a pointless exercise in masochism. Zig is an incremental improvement; an improvement, granted, but it eliminates no problems, only alleviates them.

      If I had to pick another (existent) language to be used in places where c is used, it would be one of:

      • nim. I'm admittedly least familiar with this one, but it seems to have a very sane design

      • common lisp. It doesn't go ‘small’ (so, no microcontrollers), but it does go ‘low’ (e.g.); so depends on use case here

      • ats. Can effectively be used wherever c can, as it compiles to c. (Nim does too, but far less transparently.) Linear+refinement&dependent types, for all that fp goodness. Famously esoteric, complex, and inconsistent

      4 votes
      1. [4]
        lonjil
        (edited )
        Link Parent
        Common Lisp is the language I use most often ^_^'. When I say low level, I mean low level. Very exact control over what's going on, no runtime going around doing stuff. Compiling to C does not...

        Common Lisp is the language I use most often ^_^'. When I say low level, I mean low level. Very exact control over what's going on, no runtime going around doing stuff. Compiling to C does not give you that. You can compile any language to C but if it has garbage collection it probably won't be a good idea on microcontrollers, even if it's small.
        Should be noted that when Common Lisp is used for stuff like operating systems it is with a lot of extensions that make it not really CL anymore. Like, not being able to use most of the language because you can't invoke the GC. Most of Mezzano is of course higher level than that, but Mezzano also has a fair bit of assembly code written with s-expressions.

        Zig to me seems to give more control than C, while also being much nicer to write and having some very interesting abstraction features, especially the compile time stuff. Someone even implemented borrow checking! Writing Zig has actually been pretty fun.

        "Famously esoteric, complex, and inconsistent" this sounds like the exact opposite of what I want :p

        3 votes
        1. [3]
          Moonchild
          Link Parent
          Nim is reference-counted, which will work if your microcontroller is big enough for dynamic allocation. Beyond that—again, I don't know very much nim, but I expect that it allows you to pass...

          can compile any language to C but if it has garbage collection it probably won't be a good idea on microcontrollers, even if it's small

          Nim is reference-counted, which will work if your microcontroller is big enough for dynamic allocation.

          Beyond that—again, I don't know very much nim, but I expect that it allows you to pass around fixed-size buffers, same as you would in c.

          Someone even implemented borrow checking!

          I'm not a fan :P

          "Famously esoteric, complex, and inconsistent" this sounds like the exact opposite of what I want :p

          Fair enough


          I do recommend giving ats a look, though; despite the complexity, it really just amounts to a layer of static analysis and typechecking atop c.

          3 votes
          1. pvik
            Link Parent
            Nim by default uses a reference counting garbage collector, but it also provides other GCs. The ARC GC could work well for more hand-on memory management needs.1

            Nim is reference-counted

            Nim by default uses a reference counting garbage collector, but it also provides other GCs. The ARC GC could work well for more hand-on memory management needs.1

            2 votes
          2. lonjil
            Link Parent
            I am also not a fan of borrow checking :) Just pointing out the flexibility of the comptime system. C is kinda shit for a lot of reasons. Adding more safety doesn't make me want to use it more. If...

            I am also not a fan of borrow checking :)
            Just pointing out the flexibility of the comptime system.

            I do recommend giving ats a look, though; despite the complexity, it really just amounts to a layer of static analysis and typechecking atop c.

            C is kinda shit for a lot of reasons. Adding more safety doesn't make me want to use it more. If I had to use C for something, then such a layer could be really useful, but I'd rather avoid C.

            1 vote
      2. pvik
        Link Parent
        uLisp is great for a lisp-y experience working with micro-controllers!

        common lisp. It doesn't go ‘small’ (so, no microcontrollers)

        uLisp is great for a lisp-y experience working with micro-controllers!

        1 vote
    2. JRandomHacker
      Link Parent
      I'm only a novice zig tinkerer myself, but I love it so far. Not just from a language standpoint, but from a community/development standpoint too - it really feels like the people involved care...

      I'm only a novice zig tinkerer myself, but I love it so far. Not just from a language standpoint, but from a community/development standpoint too - it really feels like the people involved care about software and software development in the way that I want to/wish more people did.

      3 votes
  2. Adys
    Link
    Since I never write in these threads… I just posted on Twitter about the self-made keyboard layout I have been using for the past 15 years. (Thought it was 10 but turns out, I'm old)...

    Since I never write in these threads…

    I just posted on Twitter about the self-made keyboard layout I have been using for the past 15 years. (Thought it was 10 but turns out, I'm old)

    https://twitter.com/Adys/status/1362167154133581828

    I would recommend it to any curious programmer. See the Twitter thread for the feature list. Don't let 'custom layout' scare you: it's basically qwerty; it's the special character keys that have been remapped :)

    3 votes