Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

General Q&A about programming, scripting, software design & architecture, process, tools, testing, and more.

Filters (None)
92%
+24 −0
What is HEAD in Git?

In Git documentation, there are lots of references to the term "HEAD". But what exactly is it? Some places refer to it as "a pointer to the current branch". So it's a branch? What is it used for?

1 answer  ·  posted 2y ago by hkotsubo‭  ·  last activity 1y ago by hkotsubo‭

91%
+19 −0
Should a salt be stored in the same database as the hash?

To protect against dictionary and rainbow table attacks it is well known that passwords should be salted before hashing. The salt (unique to each password) gets stored with the hash, often in the s...

5 answers  ·  posted 3y ago by jla‭  ·  last activity 3mo ago by bencurthoys‭

90%
+18 −0
What must a C compiler do when it finds an error?

What exactly must a C compiler do when it finds a compile-time error? The most obvious kind of errors are language syntax errors, but the C standard also speaks of constraints, which are rules tha...

1 answer  ·  posted 3y ago by Lundin‭  ·  edited 2y ago by ghost-in-the-zsh‭

90%
+18 −0
Does the location of an import statement affect performance in Python?

When writing Python-based apps (e.g. Django, Flask, etc.), it's often the case that import statements can be found all over the place, often more than once for the same module. For example, you can...

1 answer  ·  posted 3y ago by ghost-in-the-zsh‭  ·  last activity 3y ago by ghost-in-the-zsh‭

90%
+17 −0
What is the purpose of `if __name__ == '__main__'`?

I often see the construct if __name__ == '__main__' in Python code. For example, the queens.py demo in the Python repository ends with these two lines: if __name__ == "__main__": main() Ho...

1 answer  ·  posted 2y ago by J-hen‭  ·  last activity 2y ago by hkotsubo‭

89%
+15 −0
How should we share some content between two otherwise-independent git repositories?

We have two teams, dev and doc, and I'd like them to have shared access (via git) to a common subset of content. Specifically, I would like the examples that are used in the doc and that are scrip...

4 answers  ·  posted 3y ago by Monica Cellio‭  ·  last activity 3y ago by Monica Cellio‭

88%
+14 −0
Why are list comprehensions written differently if you use `else`?

The following list comprehension worked when I tried it: [num for num in hand if num != 11] But this doesn't work: [num for num in hand if num != 11 else 22] It gives a SyntaxError, highlightin...

2 answers  ·  posted 2y ago by true_blue‭  ·  last activity 5mo ago by Karl Knechtel‭

88%
+14 −0
Is strcpy dangerous and what should be used instead?

I heard rumours that the strcpy function is dangerous and shouldn't be used. Supposedly it can be exploited to create buffer overflows somehow. And indeed when I compile my C code in the admittedl...

2 answers  ·  posted 3y ago by Lundin‭  ·  last activity 1mo ago by Lundin‭

88%
+14 −0
How does Zalgo Text work, and how can I prevent my application from accepting it?

A Zalgo Text is something like this: T̃͟͏̧̟͓̯̘͓͙͔o̤̫͋ͯͫ̂ ̥͍̫̻͚̦͖͇̌ͪ̇ͤ̑̐͋̾̕i̢͖̩͙͐͑ͬ̄̿̍̚ͅn̵̢̼̙̳̒̄ͥ̋̐v̡̟̗̹̻̜͕̲ͣ̐ͤͤ͒́oͫ͂̆͑ͩ҉͇̰͚̹̠̫͔̗k̷̭̬̭͙̹̺̯ͩ̌̾̒̋̓ͤ͛͘͠e̥͙̓̄̕ ̵̫͈ͪţ̱̺̺̑̿̉̌͛̂̇h͙̣̬̓̂͞ę̡̲̟͎͉̟͛̓̉̆̉͘ ͬ̒...

1 answer  ·  posted 3y ago by hkotsubo‭  ·  last activity 5mo ago by hkotsubo‭

88%
+13 −0
Different behavior with relative imports when using flask vs py

I have a small new Python 3.8 Flask project with some relative import quirks. For the DB I use SQLAlchemy with Flask-Migrate. My project has the following general structure: controllers/ static/ te...

1 answer  ·  posted 3y ago by luap42‭  ·  last activity 3y ago by ajv‭

87%
+12 −0
For scripting what are the pros and cons of command line arguments versus capturing input at the start?

Let's say I have a script that needs the user to set X number of variables at the start. One can either Pass the arguments in on the command line. Start the program and then have the user input...

6 answers  ·  posted 3y ago by Charlie Brumbaugh‭  ·  last activity 10mo ago by Dirk Herrmann‭

87%
+12 −0
What are statements and expressions?

When I have tried to read technical explanations of the syntax rules for programming languages, and when I am trying to decipher error messages, I often encounter the terms expression and statement...

4 answers  ·  posted 9mo ago by Karl Knechtel‭  ·  last activity 9mo ago by Dirk Herrmann‭

87%
+12 −0
What compiler options are recommended for beginners learning C?

When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chas...

1 answer  ·  posted 3y ago by Lundin‭  ·  edited 2y ago by Lundin‭

87%
+12 −0
How do I support tab completion in a python CLI program?

I spend a lot of time writing CLI tools in Python, and I would like to support tab-completion in a style similar to Git. For example, subcommands should be tab-completable, options should expand ba...

1 answer  ·  posted 2y ago by ajv‭  ·  last activity 2y ago by hkotsubo‭

87%
+12 −0
What does the static keyword do in C?

What exactly does the static keyword do in C? I have seen it used in several diverse contexts: 1) As a variable outside a function: #include <stdio.h> static int x = 5; int main (void) ...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 11mo ago by Lundin‭

87%
+12 −0
Are there best practices for sticking conditions in WHERE clauses vs the JOIN statement?

Lets say I have two tables, A and B and I need to join a subset of them. Is there best practices of sticking the conditions in the WHERE clause like this, SELECT * FROM A JOIN B on a.fk_b = b....

3 answers  ·  posted 3y ago by Charlie Brumbaugh‭  ·  last activity 7mo ago by billkarwin‭

86%
+11 −0
Does using an Integer have any speed/performance benefits over a string in JSON

I'm working on an API to respond some data about a bunch of orders and items. The order and item numbers are always an integer (it's the order.id and item.id value, respectively). Originally the re...

3 answers  ·  posted 3y ago by Welz‭  ·  last activity 3y ago by .                                                .‭

86%
+11 −0
What is undefined behavior and how does it work?

I have created this sensational program: #include <stdio.h> int* func (void) { int local=5; return &local; } int main (void) { printf("%d\n", *func()); } This prints 5 even thoug...

1 answer  ·  posted 3y ago by Lundin‭  ·  last activity 3y ago by Lundin‭

86%
+11 −0
Can regex be used to check if input conforms to a very strict subset of HTML?

Tldr; I don't need to parse HTML, but I need to check if user submitted input conforms to a very strict subset of HTML. Can regex be a suitable tool for this? Details I have a frontend sanitiser th...

4 answers  ·  posted 3y ago by jla‭  ·  last activity 3y ago by Stephen C‭

86%
+11 −0
When would one not want to return an interface?

Consider the following method as an example: List<int> Foo() { // ... } Are there any disadvantages of returning an interface instead of a concrete implementation in C#? IList<i...

3 answers  ·  posted 1y ago by Moshi‭  ·  last activity 11mo ago by matthewsnyder‭

86%
+11 −0
Alternatives to `EXPLAIN ANALYZE` for queries that won't complete

I have a large and complex PostgreSQL SELECT query that I would like to make faster. EXPLAIN suggests it should run quickly, with the worst parts being scans of a few thousand rows. When run, it do...

2 answers  ·  posted 7mo ago by Emily‭  ·  last activity 7mo ago by matthewsnyder‭

86%
+11 −0
Git: How to clone only a few recent commits?

How do I clone the repository with only part of the history? For example, let's say I want to download only the last 5 commits out of thousands.

2 answers  ·  posted 8mo ago by matthewsnyder‭  ·  last activity 8mo ago by hkotsubo‭

86%
+11 −0
What is malloc's standard-defined behavior with respect to the amount of memory it allocates?

I recently told a friend that malloc(n) allocates and returns a pointer to a block of at least N bytes of memory, as opposed to exactly N; that it is allowed to allocate 'extra' memory to meet e.g....

2 answers  ·  posted 2y ago by ajv‭  ·  last activity 2y ago by bta‭

86%
+11 −0
How to do private encapsulation in C?

I'm using an object-oriented design for my C project and trying to implement classes with private encapsulation. How do I do this? Some things I've tried that are problematic: Using a struct f...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 1y ago by Lundin‭

86%
+11 −0
Should I check if pointer parameters are null pointers?

When writing any form of custom function such as this: void func (int* a, int* b) Should I add code to check if a and b are null pointers or not? if(a == NULL) /* error handling */ When po...

4 answers  ·  posted 2y ago by Lundin‭  ·  last activity 2y ago by Dirk Herrmann‭

85%
+10 −0
Is it possible to undo a git reset?

For some reason, I just wanted to undo a commit on my git repository, which I've done with the following command: git reset --soft HEAD~1 So far, so good. However, by mistake I issued the comma...

2 answers  ·  posted 2y ago by celtschk‭  ·  edited 2y ago by Alexei‭

85%
+10 −0
Vim: how to search for all instances of a string, except for those that are between two specific strings

Using Vim, I am trying to search for all instances of a specific string, except for those that fall somewhere in between two other specific strings. For example, I want to determine all instances ...

2 answers  ·  posted 2y ago by Trevor‭  ·  last activity 2y ago by Dirk Herrmann‭

85%
+10 −0
How to manage user-specific application data on Linux?

I am developing an application that targets Linux-based OS, and I need to store the user's configuration, metadata and other things in a persistent way (i.e. on the file system). I know that one c...

3 answers  ·  posted 1y ago by Björn‭  ·  last activity 1y ago by celtschk‭

85%
+10 −0
Destroy std::mutex referenced but not owned by std::unique_lock?

Is it correct to destroy a mutex which is referenced but not owned by an unique_lock as in this code? { std::unique_ptr<std::mutex> mutex = std::make_unique<std::mutex>(); std::u...

1 answer  ·  posted 3y ago by Estela‭  ·  last activity 3y ago by Angew‭

c++
85%
+10 −0
Scheme for cross-platform warning control?

tl;dr I'd like to learn a compact, cross-compiler way of selectively suppressing compiler warnings. Consider the case where you really mean to make an exact floating-point comparison using ==, o...

1 answer  ·  posted 3y ago by dmckee‭  ·  last activity 3y ago by Someone‭

85%
+10 −0
What is CPU endianness?

I was fooling around with the following C code on my trusty old x86 PC: #include <stdint.h> #include <stdio.h> int main (void) { uint32_t u32 = 0xAABBCCDD; uint8_t* ptr = (u...

1 answer  ·  posted 3y ago by Lundin‭  ·  last activity 3y ago by Lundin‭

85%
+10 −0
What does the "\s" shorthand match?

I've seen some regular expressions (regex) using \s when they want to match a space, but I noticed that it also matches line breaks. Example: the regex [a-z]\s[0-9] (lowercase ASCII letter, follow...

1 answer  ·  posted 3y ago by hkotsubo‭  ·  last activity 2y ago by hkotsubo‭

85%
+10 −0
Are "strong passwords" at all meaningful?

Whenever registering to diverse sites on the net, you are often forced to enter a so called "strong password", which would ideally contain both upper case letters, lower case letters, digits, and s...

4 answers  ·  posted 4mo ago by Lundin‭  ·  last activity 1d ago by matthewsnyder‭

85%
+10 −0
What is C23 and why should I care?

The C language has gone through many iterations and the latest one not yet released is informally called "C23", supposedly because they hoped to release it in 2023. The latest draft version N3096 i...

1 answer  ·  posted 8mo ago by Lundin‭  ·  last activity 8mo ago by Lundin‭

c c23
85%
+10 −0
How to properly use malloc?

I have seen this construct quite a lot: int *p = (int*) malloc(n * sizeof(int)); Is this how it should be? What is the proper way to use malloc? I have also seen this: int *p = malloc(n * size...

3 answers  ·  posted 2y ago by klutt‭  ·  last activity 9mo ago by Lundin‭

84%
+9 −0
Behavior of Pointer Arithmetic on the Stack

Consider the following code: #include <stdio.h> int main() { int a = 5; int b; ++*(&b + 1); printf("%d\n", a); return 0; } The output is as expected: 6 ...

4 answers  ·  posted 2y ago by Josh Hyatt‭  ·  last activity 2y ago by Alexei‭

84%
+9 −0
Is it dangerous to use json.loads on untrusted data?

I manage a wsgi application that accepts JSON data via POST from potentially untrusted sources. Normally it is treated as a text blob and never parsed, but there is a value in the expected input th...

1 answer  ·  posted 2y ago by ajv‭  ·  last activity 2y ago by hkotsubo‭

84%
+9 −0
Open file in script's own folder

I have a Python script that needs to access some data (or configuration) file in its very own folder. For example, say script.py does something like this: with open('data.txt') as file: data ...

2 answers  ·  posted 2y ago by J-hen‭  ·  last activity 3mo ago by Karl Knechtel‭

84%
+9 −0
Are there references in C?

When reading posts at programming sites such as this one, I frequently encounter people saying things like: "There is no pass-by-reference in C, everything is passed by value." People claiming su...

3 answers  ·  posted 2y ago by Lundin‭  ·  last activity 10mo ago by Alexei‭

84%
+9 −0
grep AND search for multiple words in files

I have text (xml actually) files. Some files contain 'foo', some contain 'bar', some contain neither and some contain both. It's the both I'm interested in. How do I do an AND search on words in...

5 answers  ·  posted 11mo ago by mcalex‭  ·  last activity 10mo ago by tripleee‭

84%
+9 −0
memcmp(3) memory containing invalid values

What does it mean that we can use memcmp(3) on invalid values? ISO C allows comparing an invalid value through memcmp(3), because it doesn't read the value, but rather its representation, and "rea...

2 answers  ·  posted 1y ago by alx‭  ·  last activity 1y ago by Lundin‭

84%
+9 −0
How to override default string formatter?

It is possible to create a new formatter class by subclassing string.Formatter class and then to use it like myformatter.format("{foo:customformat}", foo=foo). It's not super-convenient though, and...

1 answer  ·  posted 3y ago by luser‭  ·  edited 3y ago by Alexei‭

84%
+9 −0
Why don't format specifiers work with lists, dictionaries and other objects?

When I want to print a number or a string, I can use f-strings (Python >= 3.6) or str.format, and I can use just the variable between braces, or use format specifiers. Ex: num, text = 10, 'abc' ...

1 answer  ·  posted 3y ago by hkotsubo‭  ·  edited 3y ago by sth‭

84%
+9 −0
Understanding mutable default arguments in Python

Consider this code example: def example(param=[]): param.append('value') print(param) When example is repeatedly called with an existing list, it repeatedly appends to the list, as ...

4 answers  ·  posted 7mo ago by Karl Knechtel‭  ·  last activity 5mo ago by matthewsnyder‭

84%
+9 −0
What is the point of pipx?

Background Many Python programs now recommend installing with pipx, and there is a sense that you shouldn't install with pip anymore, you should use tools like pipx. Main Question However, what ...

3 answers  ·  posted 8mo ago by matthewsnyder‭  ·  last activity 7mo ago by tripleee‭

84%
+9 −0
What is a good modern language to use for a Business Rules project?

This is a rather vague question, but I'm trying to solve a specific problem and I'm inexperienced in most of the potential solutions, so please forgive the inherent ambiguity. I have access to a d...

3 answers  ·  posted 3y ago by Sigma‭  ·  last activity 10mo ago by matthewsnyder‭

84%
+14 −1
What's the correct way to merge a branch and its dependent branch back to master?

In git I branched feature-A from master. To reduce eventual merge conflicts later, I branched feature-B, which heavily overlaps and depends on A, from feature-A. A build of the feature-B branch s...

2 answers  ·  posted 3y ago by Monica Cellio‭  ·  edited 2y ago by hkotsubo‭

83%
+8 −0
How to declare variable-length arrays correctly?

This is meant as a FAQ Q&A regarding variable-length arrays (VLA). The two bugs described below are surprisingly common. I'm trying to use the variable-length arrays feature of C99 (and newe...

1 answer  ·  posted 2y ago by Lundin‭  ·  last activity 8mo ago by Lundin‭

83%
+8 −0
Why does Firefox block based on a restrictive default-src directive, when more specific, more permissive *-src exist?

I am working on a website which unfortunately uses a mix of linked and inline CSS and Javascript (and, even more unfortunately, I can't do a lot about the use of inline CSS and Javascript), and am ...

1 answer  ·  posted 2y ago by Canina‭  ·  last activity 2y ago by Moshi‭

83%
+8 −0
Is MISRA-C useful outside safety-critical and embedded programming?

When discussing best or safest C programming practices with various C gurus on the Internet, the "MISRA-C guidelines for the use of C language in critical systems" often pops up as a source. This ...

1 answer  ·  posted 3y ago by Lundin‭  ·  last activity 3y ago by ghost-in-the-zsh‭