9,543 reputation
12241
bio website
location
age
visits member for 3 years, 9 months
seen 7 hours ago

Jun
3
comment Are there advantages for using recursion over iteration - other than sometimes readability and elegance?
@RobertHarvey The expense can certainly be measured, I can whip up an example if you insist. Whether it actually matters in the majority of code (where any individual function only accounts for 0.5% of total run time and most of the time is spent in business logic, not looping or calling functions) is another issue, but the same is true for any micro optimization. Another thing, it seems strange to say overflowing the stack is "expensive". In most environments, it means data corruption or an insurmountable run-time error. That's not "expensive", that's "broken".
Jun
3
comment Are there advantages for using recursion over iteration - other than sometimes readability and elegance?
The recursive version can not only be more readable, it can also be more writable. While this is generally a lesser factor than readability (code is read far more often than it is written), it does matter since all good programmers are lazy ;-) The overarching advantage is that the recursive version is (usually) simpler, and this reflects on both reading and writing the code.
Jun
3
comment Are there advantages for using recursion over iteration - other than sometimes readability and elegance?
@RobertHarvey Function calls are not expensive, but they are almost always more expensive than merely going back to the start of the loop body. jmp vs (push r1, r2 and jmp) in C, "set up a whole frame object" versus "change the interpreter's instruction pointer" in CPython. A function call simply needs to do more than a loop backedge. The more important question then is whether you can do the required state management more effectively than the language implementation.
Jun
2
comment How can I be certain that my code is flawless?
Fun fact: One can test for all primes that fit into int. It's not even a lot, there are "only" about 2^31/ln(2^31) ~= 10 million prime numbers smaller than INT_MAX.
Jun
2
comment Is this simple XOR encrypted communication absolutely secure?
@Zack There are many problems with OTPs, but none threatens confidentiality. Note that even if you perfectly guess the previous message's plantext+key, the next message is encrypted with an entirely new, independent key (of considerable size too). There is nothing to adapt to over multiple interactions.
Jun
1
comment Is this simple XOR encrypted communication absolutely secure?
"Why aren't OTPs practical" might be another good question (for Information Security), but it's certainly a separate question.
Jun
1
comment Is this simple XOR encrypted communication absolutely secure?
Other than the specific scheme to coordinate which part of the key to use, this is just a one-time pad. But under closer inspection it turns out to not actually be useful for 99% of use cases.
Jun
1
answered Should sanity be a property of a programmer or a program?
May
29
comment If Scheme is untyped, how can it have numbers and lists?
@Evicatos Strictly speaking, not even atoms are necessary, only closures. Look up church numerals and related constructions. Of course, this is extremely convoluted and slow. But so is emulating lists with closures, though to a lesser degree.
May
29
comment If Scheme is untyped, how can it have numbers and lists?
@Dokkat Because it's not. What's the type of (if (the-stars-align) nil 5))?
May
29
comment If Scheme is untyped, how can it have numbers and lists?
@JimmyHoffa I agree with you about what OP is explicitly asking for. But I think OP is asking that because of an unstated confusion about the exact issue my answer discusses.
May
29
comment If Scheme is untyped, how can it have numbers and lists?
@RobertHarvey That is not what I'm trying to say. My point is that "type" can mean one of two very different things.
May
29
comment If Scheme is untyped, how can it have numbers and lists?
@RobertHarvey What do you think that might be?
May
29
answered If Scheme is untyped, how can it have numbers and lists?
May
29
comment Is it feasible and useful to auto-generate some code of unit tests?
@skiwi I don't say coverage is meaningless, but it is a metric and hence subject to "gaming": One can achieve high coverage without actually having decent tests (by writing tests that cover that code but don't verify meaningful tests). Meaningful tests would verify that a change to implementation details doesn't affect behavior, at least as much if not even more (note that covering a given line does not cover all behaviors that can occur; trivial example is anything including division by a variable).
May
29
comment Is it feasible and useful to auto-generate some code of unit tests?
@skiwi Coverage produced for the sake of coverage doesn't buy you anything (except appease mindless insistence on metrics). Tests should test what matters, such as adherence to the documented API and robustness against invalid inputs. Lack of coverage can either mean that there are cases you've implemented but not tested, or pointless code. Assuming the latter is putting the cart before the horse. Tests as you propose them only test that (1) the automatic test generation is correct and (2) the VM executes the code you wrote correctly.
May
29
comment Is it feasible and useful to auto-generate some code of unit tests?
It seems that a test generated this way is primarily an echo chamber for the implementation, i.e. is confirms that the implementation does what you wrote it to do, not whether this is sensible from any other perspective. It might incidentally produce tests that are meaningful w.r.t. the requirements and the contract of the code, but doesn't seem intrinsically biased towards that sort of test.
May
28
revised Why do we need a format for binary executable files
added 122 characters in body
May
28
comment Why do we need a format for binary executable files
A stream of machine code is also data that can be handled by another program. Sure, it doesn't have a whole lot of metadata, and metadata is useful, but your examples don't seem like good examples of that. "Calling another binary" (I assume you mean creating a process?) is no different from starting up the process that "calls another binary". Context switching has nothing to do with that metadata, it works with any code whatsoever (e.g. JIT compiled code). Who owns what memory address is already managed by virtual memory, and it works for any allocated memory without such metadata.
May
28
answered Why do we need a format for binary executable files