10 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?

20 comments

  1. [7]
    ali
    Link
    Got listed as A contributor on a bigger GitHub project for finding a bug. Now I’m in the mood to contribute to more things. Any projects you have contributed to?

    Got listed as A contributor on a bigger GitHub project for finding a bug. Now I’m in the mood to contribute to more things. Any projects you have contributed to?

    7 votes
    1. Bauke
      Link Parent
      Tildes can always use more contributors, check out the contributing doc if you're interested. :D

      Tildes can always use more contributors, check out the contributing doc if you're interested. :D

      10 votes
    2. [2]
      thundergolfer
      Link Parent
      An awkward number of my "contributor" badges on large projects are README fixes 😅.

      An awkward number of my "contributor" badges on large projects are README fixes 😅.

      6 votes
      1. acdw
        Link Parent
        That's useful too! I always catch little typos, think about changing them, then don't. I'm still using the exuse that someone was mean to me once. But I can get over it!

        That's useful too! I always catch little typos, think about changing them, then don't. I'm still using the exuse that someone was mean to me once. But I can get over it!

        3 votes
    3. [2]
      CrazyOtter
      Link Parent
      Well done, any particular language you're looking to work in?

      Well done, any particular language you're looking to work in?

      2 votes
      1. ali
        Link Parent
        I feel comfortable enough to contribute in js, python and java. Thinking of maybe some creative stuff too. Maybe some projects I can use to teach, too. That’s actually how I got to the last project

        I feel comfortable enough to contribute in js, python and java. Thinking of maybe some creative stuff too. Maybe some projects I can use to teach, too. That’s actually how I got to the last project

        3 votes
    4. ffmike
      Link Parent
      Contributing to Rails, way back when, was the fastest way for me to establish my credentials when abandoning Microsoft-land for open source work. These days, most of my contributions to public...

      Contributing to Rails, way back when, was the fastest way for me to establish my credentials when abandoning Microsoft-land for open source work.

      These days, most of my contributions to public projects are typo fixes. I still commit tons of code at work, and I've started up a new private side project which may or may not go somewhere...

      2 votes
  2. [9]
    acdw
    Link
    I'm currently learning C for real (as opposed to just cobbling stuff together), and it made me think about utf8. Any languages use utf8 by default?

    I'm currently learning C for real (as opposed to just cobbling stuff together), and it made me think about utf8. Any languages use utf8 by default?

    5 votes
    1. [2]
      joplin
      Link Parent
      Swift does. You can have variable names be almost any set of unicode characters (er... code points... whatever), except for mathematical symbols. They exclude mathematical symbols because you can...

      Swift does. You can have variable names be almost any set of unicode characters (er... code points... whatever), except for mathematical symbols. They exclude mathematical symbols because you can use those for creating your own operators. Want a dot product operator that uses the actual dot product symbol? You can do that! It's pretty cool.

      4 votes
      1. acdw
        Link Parent
        That is cool! One thing I like about Haskell.

        That is cool! One thing I like about Haskell.

        1 vote
    2. [3]
      whbboyd
      Link Parent
      Rust's strings are UTF-8. This is actually considered a safety guarantee: it is not possible, without using unsafe, to put bytes which do not correspond to a valid sequence of UTF-8 code points...

      Rust's strings are UTF-8. This is actually considered a safety guarantee: it is not possible, without using unsafe, to put bytes which do not correspond to a valid sequence of UTF-8 code points into a string.

      4 votes
      1. [2]
        acdw
        Link Parent
        Oh cool! I'll have to try rust again. I got lost on borrowing last time I tried it.

        Oh cool! I'll have to try rust again. I got lost on borrowing last time I tried it.

        1 vote
        1. pvik
          Link Parent
          I have been having a lot of fun learning/using Rust the last several months. Coming from a C background, I really liked Learn Rust the dangerous way to get my feet wet with rust.

          I have been having a lot of fun learning/using Rust the last several months. Coming from a C background, I really liked Learn Rust the dangerous way to get my feet wet with rust.

          2 votes
    3. [2]
      ainar-g
      Link Parent
      Not sure, what you mean by “use UTF-8 by default”, but in Go, both the programme source code and strings are required to be UTF-8 by the language specification.

      Not sure, what you mean by “use UTF-8 by default”, but in Go, both the programme source code and strings are required to be UTF-8 by the language specification.

      3 votes
      1. acdw
        Link Parent
        I mean that! Thanks for the info -- it looks like I'm going to try bouncing between Go and Rust, starting maybe in a few months.

        I mean that! Thanks for the info -- it looks like I'm going to try bouncing between Go and Rust, starting maybe in a few months.

        3 votes
  3. ainar-g
    Link
    Here is a nice riddle for yall: How do you get the exit status of a non-last command in a pipeline in POSIX shell without using temporary files, FIFOs, and alike? The POSIX shell bit is important....

    Here is a nice riddle for yall: How do you get the exit status of a non-last command in a pipeline in POSIX shell without using temporary files, FIFOs, and alike?

    The POSIX shell bit is important. In Bash you have PIPESTATUS:

    #!/usr/bin/env bash
    
    ( exit 7 ) | ( exit 2 )
    
    echo "first: ${PIPESTATUS[0]}, second: ${PIPESTATUS[1]}"
    
    2 votes
  4. [3]
    xxzozaxx
    Link
    Is there a list of C problem. like dangling pointer double free, etc etc. I don't know what they called, maybe list of memory management issues. and if there is a basic issue from which these...

    Is there a list of C problem.
    like

    1. dangling pointer
    2. double free, etc etc.

    I don't know what they called, maybe list of memory management issues. and if there is a basic issue from which these issues came, but I don't want someone to tell me it has no GC, or something like that. this is not a problem.

    1 vote
    1. joplin
      Link Parent
      Are you in the process of debugging a memory issue? If so, there are a lot of great tools for that. What OS are you programming for? For macOS/iOS, there's Address Sanitizer, the Leaks instrument,...

      Are you in the process of debugging a memory issue? If so, there are a lot of great tools for that. What OS are you programming for? For macOS/iOS, there's Address Sanitizer, the Leaks instrument, the Allocations instrument, Zombies, guard malloc, and guard edges. For Linux and Unix there's valgrind. (I think Valgrind also works on macOS and Windows, too, but am not positive.) I'm sure Microsoft has some memory debugging tools in VSCode and Visual Studio.

      There's also static analysis of your code. If you're building with llvm you can use the clang static analyzer to find memory issues, for example.

      3 votes