2021-03-18 15:44:37

Don't get attached to your code.  Prototypes are prototypes.  The first version of Synthizer's HRTF implementation was written entirely in Python with Numpy and a hacky audio library called Pyo that crashes the process if you even breathe on it wrong.  I don't even have the code for it anymore.  You can write versions of software with the intent that you will delete them in 2 months because they're not the real thing yet.  This isn't always applicable, but if you don't know how to do the thing and if the thing is small, then doing the thing incredibly badly but as fast as you can to learn what you need to know is often more productive than trying to do it right the first time.

Don't overpromise even to yourself.  Know what is going to b in the app.  Plan for exactly those features and no more.  If you get exactly those features then trying to add one more thing is going to need a rewrite, it's a success as long as the features it was supposed to have are there and working.  It takes a great deal more experience than you probably have to manage to do that while leaving it open-ended enough to keep going, so don't try.  It's fine for projects to be finished.

Deadlines won't help.  Deadlines just mean you do the same amount of thinking but you're running late so now you're working 14 hour days.  I guess if your problem is entirely discipline it can help with that but being under time pressure isn't going to make "I don't know what to do o no o no my code is fucked and I have to rewrite" go away.

My Blog
Twitter: @ajhicks1992

2021-03-19 15:42:39

@25
Also, I personally feel like your choice of language and tooling helps a little with this.

I had to change the signature of a function in Dart yesterday. It took me about 15 seconds to change the signature and then the function body. After that, it was probably about 2 hours of (not exactly frenetic) work to change the rest of the code base, because the dart analyser wouldn't shut up about invalid calls to that function.

Admittedly this was only a small change, in a small app, but the point still stands.

Other than that, I suppose just to back Camlorn up: It's better to have written and learnt from 10000 lines of dodgy code, than to have nothing to show for 0 lines.

-----
I have code on GitHub

2021-03-19 15:56:10

I don't really follow any design patterns. For example in my kernel I don't have unit tests I can run. I should probably add them, but each unit test has to be a build of the smaller form of the actual kernel image -- there's no real way I can necessarily test things quickly. I know I should add them, I really know I should, and I probably will. What's difficult for me with things like that is finding out precisely what to test and what to ignore. I also don't have a self-test framework either.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2021-03-19 16:38:53

@28
Unit testing takes experience but is a good idea, though I'm not sure how to do so for a kernel.  I'm sure someone has solved this problem.

Synthizer has some, and it'll be getting more.  One thing that can be useful for the weird cases is gold master testing: don't test that thing x is right, instead check the output of thing x against the previous output of thing x and see if it changed.  This is what I plan to do for Synthizer, since it is entirely possible to say "yep this sounds right", then capture an audio file of it.

You may also look at libfuzzer and similar fuzzing technologies: if you can compile parts of the kernel outside the environment it needs to run in, e.g. network parsers or whatever, something like that can find crashes.

Clang-analyzer will run over the kernel no problem.  It's static analysis so running in the kernel's compiled environment isn't necessary.  This can tell you things like "there is definitely a memory leak here", though I don't know what you have to annotate with or anything if you're providing a custom allocator.

My Blog
Twitter: @ajhicks1992

2021-03-19 17:13:23

@29, I don't think I can run clang-analyzer over the code -- I'm using Rust, not C/C++. Rust performs quite a bit of static analysis of its own, and though there are other tools like Miri and Mirai that allow even more, I can't seem to get those working on Rust Nightly (but clippy works).

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2021-03-19 18:04:21

Ah, yeah.  Rust makes a great deal of this moot by the nature of being Rust, so eh.

But if you are in Rust you can easily unit test inline.  In the same file as the code:

#[cfg(test)]
mod tests {

#[test]
fn passes() {
}
}

which will have access to the private content of the module and can import dev dependencies, e.g. in your case you probably want proptest or quickcheck, but see also assert_json_diff if you're willing to annotate things with Serde (I believe there is a no-std version of Serde, but maybe not).

My Blog
Twitter: @ajhicks1992

2021-03-20 00:59:14

I as well tend to start a lot of projects and end up reaching a workable state and then never continuing them.
I guess we could say my issue is more that I don't design anything thoroughly, but mostly that I'm doing a project to learn a particulartechnology or what have you.
I know for a fact I'd suck hard at trying to keep an API stable.
For example, cytolk used to be OOP initially. You'd handle all operations from a class which would load the library on instantiation and unload it on deletion. But then I reverted on using functions because that way older apps which used the python tolk bindings could switch with ease.
I also attempted to build an editor which'd parse asciimath and turn it into mathml, but then the thing became a problem where I'd have to fight with the underlying parser and I did not have time nor knowledge to build one from scratch. I did manage to find a nice one built with rust though, so I suppose I might switch  to that.

Paul