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 »

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.

Posts by Karl Knechtel‭

93 posts
66%
+2 −0
Q&A Understanding Virtual Environments for Python

Several times now, I've seen advice in tutorials, setup/install instructions for Python-based projects, etc. to use a virtual environment to keep things organized and make it simpler to manage the ...

1 answer  ·  posted 5mo ago by Karl Knechtel‭  ·  last activity 5mo ago by Karl Knechtel‭

66%
+2 −0
Q&A How does the strict aliasing rule enable or prevent compiler optimizations?

Inspired by https://meta.stackoverflow.com/questions/432242, and the relevant main-space questions. I have heard that C and C++ something called the "strict aliasing rule", which means for exa...

2 answers  ·  posted 18h ago by Karl Knechtel‭  ·  last activity 27m ago by Lundin‭

66%
+2 −0
Q&A Simultaneous comparison in Python

Using and and or correctly The left-hand side and right-hand side of these operators should both be valid operands, which should each come from a comparison. Thus, we should repeat the comparison ...

posted 3d ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A Understanding "de Morgan's laws"

While trying to understand logical 'or'/'and', I encountered another problem (I'm writing Python code here, but my question is about the logic, not about any given programming language). I have som...

1 answer  ·  posted 4d ago by Karl Knechtel‭  ·  last activity 4d ago by Karl Knechtel‭

66%
+2 −0
Q&A What happened, or is happening, to other parts of the standard library? Why are they going missing?

In Python 3.12, I noticed that some libraries seem to be missing or "deprecated": >>> import asynchat Traceback (most recent call last): File "<stdin>", line 1, in <module&gt...

1 answer  ·  posted 5mo ago by Karl Knechtel‭  ·  last activity 5mo ago by Karl Knechtel‭

66%
+2 −0
Q&A Understanding the `if __name__ == '__main__':` idiom

Whenever Python loads code from a .py file, that code gets its own namespace for global variables - so they're not truly global, but per-file values. (When you look at an imported module "from outs...

posted 5mo ago by Karl Knechtel‭  ·  edited 5mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A Understanding the `if __name__ == '__main__':` idiom

I've seen many examples of Python scripts that include a line that says: if __name__ == '__main__': Sometimes the following block contains a bunch of code, but other times it just makes a singl...

1 answer  ·  posted 5mo ago by Karl Knechtel‭  ·  last activity 5mo ago by Karl Knechtel‭

66%
+2 −0
Q&A Regex to get text outside brackets

First, we need to define some semantics. While it may not matter for your actual inputs, I propose that it should be valid for the output elements - the parts of the text found outside of brackets ...

posted 5mo ago by Karl Knechtel‭

Answer
66%
+4 −1
Q&A How can I build a string from smaller pieces?

Suppose I have some variables like: >>> count = 8 >>> status = 'off' I want to combine them with some hard-coded text, to get a single string like 'I have 8 cans of Spam®; b...

2 answers  ·  posted 1y ago by Karl Knechtel‭  ·  last activity 1y ago by Karl Knechtel‭

66%
+2 −0
Q&A How can I start my Python code, from the code itself?

Mac/Linux In this environment, Python scripts can be given a shebang line that tells the operating system that the file is a script, and what interpreter (i.e., Python) to use for it. Because # st...

posted 5mo ago by Karl Knechtel‭  ·  edited 5mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A How is this code "dividing" by a string?

Python allows for operators to be overloaded (the subject of a separate future Q&A). The / operator doesn't strictly mean division in a mathematical sense; it means whatever the operands define...

posted 5mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A Why does `distutils` seem to be missing or broken? Isn't it part of the standard library?

Understanding distutils and setuptools: the history The short version of "why does installing Setuptools fix the problem?" is that Setuptools provides its own distutils package, overriding anythin...

posted 7mo ago by Karl Knechtel‭  ·  edited 7mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A How can I manage multiple consecutive strings in a buffer (and add more later)?

This question is inspired by If I have a char array containing strings with a null byte (\0) terminating each string, how would I add another string onto the end? on Stack Overflow. Suppose I have...

2 answers  ·  posted 8mo ago by Karl Knechtel‭  ·  last activity 7mo ago by Lundin‭

Question c string
66%
+2 −0
Q&A How can I provide additional information when raising an exception?

The raise statement in Python accepts either an Exception class or an instance of that class. When used with a class, Python will create and raise an instance by passing no arguments to the constru...

posted 10mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Code Reviews Detecting balanced parentheses in Python

Command-line timing Rather than using separate code for timing, I tried running the timeit module as a command-line tool. I wrote initial versions of the implementations based on the OP and hkotsu...

posted 10mo ago by Karl Knechtel‭

Answer
66%
+4 −1
Q&A Does Python have a "ternary operator" (conditional evaluation operator like "?:" in other languages)?

Sometimes code needs to assign (or otherwise use) a value that depends on some condition. The naive approach is to use explicit branching, which in Python would look like: if some_condition(): ...

2 answers  ·  posted 12mo ago by Karl Knechtel‭  ·  last activity 12mo ago by matthewsnyder‭

Question python syntax
66%
+2 −0
Meta Should asking about book recommendations directly connected to software development be on-topic?

Are books special? When I see a question like this, I naturally transform it into a more general question about resources. Printed books aren't necessarily the best way to learn about programming ...

posted 1y ago by Karl Knechtel‭  ·  edited 1y ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A Why is git merge from rather than to?

I struggle to think of any use cases for merging from. Why was the merge command designed this way? The model here is that many developers on the same project are using branches to develop fea...

posted 1y ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Why does `distutils` seem to be missing or broken? Isn't it part of the standard library?

Sometimes when I try to install a third-party library for Python, I get an error saying that either distutils, or some part of it like distutils.core or distutils.util, could not be found. It's sho...

1 answer  ·  posted 7mo ago by Karl Knechtel‭  ·  last activity 7mo ago by Karl Knechtel‭

60%
+1 −0
Code Reviews JSON log formatter

PEP 8 Four-space indentation is the community standard. There are many strategies for wrapping long lines; I have found that it's often best to just use temporary variables to avoid wrapping lines...

posted 10mo ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Generating combinations of elements, which are themselves sequences of the same length, where the elements have no value in common at any position

This question is adapted from a question I just helped fix up on Stack Overflow. I'm giving a different motivating example which I think will make it clearer what the requirements are and why a n...

2 answers  ·  posted 5d ago by Karl Knechtel‭  ·  last activity 5d ago by Karl Knechtel‭

60%
+1 −0
Q&A Generating combinations of elements, which are themselves sequences of the same length, where the elements have no value in common at any position

Using a recursive generator There isn't anything like a built-in solution for this algorithm, but it's easy to express the desired output recursively. A valid output combination of k-many inputs l...

posted 5d ago by Karl Knechtel‭  ·  edited 5d ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Generating combinations of elements, which are themselves sequences of the same length, where the elements have no value in common at any position

Using filtered products of candidates, over combinations of first letters Let's consider the n=2 case first. (For higher n, we can use the same sort of recursive generator approach as in my other ...

posted 5d ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Common string handling pitfalls in C programming

Understanding the representation of text in C "Text" is a high level abstraction that C doesn't properly support Fundamentally, C does not have any built-in "string" type. It arguably doesn't eve...

posted 4d ago by Karl Knechtel‭  ·  edited 4d ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Simultaneous comparison in Python

I want to make multiple comparisons at once, of the same type, in a Python program. For example, to check whether all of a certain group of strings are in a longer test string; or whether a specifi...

1 answer  ·  posted 3d ago by Karl Knechtel‭  ·  last activity 3d ago by Karl Knechtel‭