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.

Activity for Karl Knechtel‭

Type On... Excerpt Status Date
Answer A: Understanding mutable default arguments in Python
Possible justifications It may make sense to use a mutable default argument in the following situations: For simplicity Consider for example an argument that should be some kind of mapping, where the function will only use it for lookup without actually mutating the provided object: ``` ...
(more)
8 months ago
Edit Post #289756 Initial revision 8 months ago
Answer A: Understanding mutable default arguments in Python
Workarounds Avoiding mutation Because problems are only caused by actually mutating the default argument, the simplest way to avoid problems is to... not do that. Pythonic code obeys command-query separation; a function should take its effect either by mutating one or more parameters (a "comman...
(more)
8 months ago
Edit Post #289754 Initial revision 8 months ago
Answer A: Understanding mutable default arguments in Python
Terminology "Mutable default argument" means exactly what the individual words would suggest: it's an argument which is supplied as the default value for that parameter, which also is mutable. To mutate an object means to change its state - for a list, that includes adding, removing, replacing or ...
(more)
8 months ago
Edit Post #289753 Initial revision 8 months ago
Question 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 one might expect: ``` >>> mylist = [] >>> example(mylist) ['value'] >>> example(mylis...
(more)
8 months ago
Comment Post #285818 Stack Exchange is dominated by Stack Overflow because it was originally an idea by and for programmers, who later realized almost as an afterthought that the same software and format could be used to build Q&A about other topics. Codidact comes years later, after seeing how the Stack Exchange model h...
(more)
8 months ago
Comment Post #289725 Proper answers to this will depend *strongly* on your exact needs. The Pickle format is about as general as is ever feasible, and is way overkill for most serialization.
(more)
8 months ago
Edit Post #289714 Post edited:
fix formatting and grammar
8 months ago
Comment Post #289714 This site is for concrete questions and answers. It isn't reasonable to expect "help" with figuring out a possible problem buried within dozens of lines of "code" (which seems to be a mixture of things that you wrote and messages that you got when you tried to do something). It's also impossible to u...
(more)
8 months ago
Suggested Edit Post #289714 Suggested edit:
fix formatting and grammar
(more)
helpful 8 months ago
Comment Post #289251 "I just can't imagine that someone would think about tuples in this kind of scenario." I think you've misunderstood. The word "tuple" here is **only** used to describe the **result of** the non-working attempt.
(more)
8 months ago
Comment Post #289700 I hadn't actually thought about using a helper class for interpreting the bits of the integer used to represent universe subsets - you might consider adding an answer to refine this idea, or proposing an edit :) (Although it's not exactly clear to me that this makes things any easier than just using ...
(more)
8 months ago
Comment Post #289707 Sorry, I don't understand how "code obfuscation" relates to the other concepts here. Aside from that, this is a good start to the discussion, but I don't feel like I've moved significantly closer towards choosing from the options I presented....
(more)
8 months ago
Edit Post #289701 Initial revision 8 months ago
Question Handling common wrong approaches and misguided motivations for basic technique questions
Background This is inspired to some extent by https://software.codidact.com/posts/289597 . I'm trying to provide a large amount of content (gradually!) that novices (mainly to Python) will find useful. The goal of the actual content is to demonstrate standard techniques and clear up common misc...
(more)
8 months ago
Edit Post #289700 Initial revision 8 months ago
Answer A: Are questions about (abstract) algorithms and datastructures considered on-topic?
As the author, this is my defense. Design and modeling are on-topic The site topicality documentation explicitly includes "Software design, architecture, or modeling" as on topic. There doesn't seem to have been any objection in the original feedback process. I formulated the question with t...
(more)
8 months ago
Comment Post #289251 It seems appropriate to show common non-working attempts, because that will help someone who is redirected here after trying one of them. I'll try to simplify the wording, and move the point about versions to a footnote.
(more)
8 months ago
Comment Post #289691 The [site topicality guidelines](https://software.codidact.com/help/on-topic) explicitly permit Q&A about "Software design, architecture, or modeling", which I think this is.
(more)
8 months ago
Comment Post #289692 Of course, that will get into language-dependent details. The languages that *do* support large integers tend to represent booleans as separate objects and not necessarily have a bit-vector abstraction, so that can incur a lot of overhead again. But the main idea here is the representation of "subset...
(more)
8 months ago
Edit Post #289692 Initial revision 8 months ago
Answer A: Optimized representation for sets?
First store the universe of potential elements as a sequence, then encode each set as an unsigned integer interpreted as follows: if the 1s bit in binary is set (1), the set contains the 0th element in the universe sequence; if the 2s bit is set, the set contains the 1st element; if the 4s bit, the 2...
(more)
8 months ago
Edit Post #289691 Initial revision 8 months ago
Question Optimized representation for sets?
I need to do a lot of calculations involving sets. There are relatively few values in the "universe" of candidates that could appear in any of the sets, but potentially very many such sets (they might not initially be distinct, either). My language has a built-in (or standard library) representati...
(more)
8 months ago
Comment Post #289605 Do you need to be able to interrupt individual calls to `do_big_task`? Or only check in between each call, whether there has been a keypress since the previous call?
(more)
9 months ago
Edit Post #289599 Post edited:
9 months ago
Edit Post #289599 Initial revision 9 months ago
Question What categories could we benefit from having?
So far, existing Meta discussion seems to have at least hinted at the possibility of using separate categories here: To shuffle closed questions out of the way (globally for Codidact) (also) For debugging help requests (discussed in passing) (also) To recommend books or other resources To p...
(more)
9 months ago
Edit Post #289598 Post edited:
HTML hack to avoid bogus links
9 months ago
Edit Post #289598 Initial revision 9 months ago
Answer A: 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 concepts; web pages may work much better. Some people like video tutorials; I personally have found th...
(more)
9 months ago
Edit Post #289597 Post edited:
9 months ago
Edit Post #289597 Initial revision 9 months ago
Question Should self-answered Q&A use separate answers for different techniques/approaches (even if there's a caveat that applies overall)?
Looking back at my own Q&A How can I build a string from smaller pieces?, the answer is incredibly long. I'm essentially showing five different ways to solve the problem - because they all exist, and well-informed developers should know about all of them. Would it make more sense to split the cont...
(more)
9 months ago
Comment Post #289584 "Would this be correct?" - Generally I don't think that this sort of thing forms the basis of a useful question for a Q&A site. Did you **try** the code? Does it give the results you expect? Does anything strange happen? It would be better to identify a concrete problem, if any, to ask about; otherwi...
(more)
9 months ago
Comment Post #289575 While generally I agree that *whereas pipx answers the question "As a user, how can I conveniently install a tool which is available via PyPi, without learning anything about Python* is an accurate summary of the intended use case - Pipx has the issue that it expects you to have Python and Pip alread...
(more)
9 months ago
Comment Post #289573 OP seems to have clearly intended that the Python program should exit after scheduling the next task, but this is a useful technique for other situations. Actually, I was hoping to prepare a more general Q&A for language-agnostic techniques for this kind of scheduling.
(more)
9 months ago
Comment Post #289514 I agree wholeheartedly, so I edited that in - even though it's unnecessary for the example as you say. After all, I could *also* have just written the separate list elements explicitly; but the point is to show a more general technique.
(more)
9 months ago
Edit Post #289514 Post edited:
use shlex.split per trichoplax's suggestion
9 months ago
Comment Post #289563 I see that you address the following to some extent in the "Encoding" section of the answer, but I think it could use some elaboration. My understanding is that Posix indeed allows filenames to contain arbitrary byte sequences aside from the 0x00 NUL byte and the path separator (0x2f byte). It's a...
(more)
9 months ago
Edit Post #289568 Initial revision 9 months ago
Answer A: How should I organize material about text encoding in Python into questions?
Here is my current thinking on the matter. 1. Regarding questions/facets that are "two sides of the same coin" - encoding vs decoding the data, reading vs. writing files - I think they should be addressed in one breath. 1. Regarding the Python documentation: I think it is better cited, on deman...
(more)
9 months ago
Edit Post #289559 Initial revision 9 months ago
Question How should I organize material about text encoding in Python into questions?
I want to write one or more self-answered Q&As on the topic of text encoding in Python, to serve as canonicals and preempt future lower-quality questions. I can think of the following things that need to be addressed: What is an encoding? What are encoding (the process) and decoding? How do I k...
(more)
9 months ago
Comment Post #289514 I don't know anything about `systemd-run`, actually. My first thought was `cron`, but that's intended for regularly re-occurring tasks. When I tried to do research on that, `at` came up.
(more)
9 months ago
Edit Post #289514 Post edited:
9 months ago
Edit Post #289514 Initial revision 9 months ago
Answer A: How can I schedule a later task in Python?
Use `at` to schedule the command, using `subprocess` from Python to invoke `at`. It doesn't even require `shell=True`. For example: ``` import shlex, subprocess subprocess.run( # `at` command to run now shlex.split("at now +10 minutes"), # shell command that `at` will schedule, ...
(more)
9 months ago