932 karma · joined Sep 18, 2020 (6y ago) · 485 submissions
comment 3y ago · link · parent
-----
I tried Embedded Rust about 4 to 6 years ago and found the experience underwhelming, as I was installing a TON of packages just to get Blinky and seeming to bypass a lot of standard Rust (no_std, no_main, use panic_halt as _, everything GPIO is unsafe, etc). The last straw was that imported Cargo packages had their absolute path somehow hardcoded in the symbol table, so my debugger would try to load, like... C:\Users\jacob\stm32-rust-thingy\app\solve.rs (and fail, because I'm not jacob and don't have his source code)
I'll give it another shot. I'm sure the "many eyes" principle (and better/more tutorials in the past few years) make the process easier now than then.
comment 3y ago · link · parent
I know ripgrep is written in Rust and works really well and "does one thing", so I'll go to its repo ( https://github.com/BurntSushi/ripgrep ) and read through a bit. First, I'm looking for a "src" folder, but that does not exist, so right off the bat I am a little uncomfortable. Nothing in the root folder looks like it would be the source. What are "complete" and "scripts" and "pkg" folders? Because those (in that order) would be what I check.
"complete" looks like command line completion. The "scripts" directory has one file, "copy-examples". "pkg" contains folders "brew" and "windows". Still lost...
I thought "crates" was like modules for Python, so I think that would only contain dependencies and stay out of there.
Finally, I relent and open "build.rs" which I suspect is something like "build.ninja" and I can figure out which node has source files. Stupid me. "build.rs" IS the source file.
Oh. No, actually, it's not all of ripgrep, in fact. It's the tip of the iceberg. The source is in crates/core/app.rs, and build does manpage compilation, registers shell completions, etc.
So, line one. I don't know what the return value App<'static, 'static> is. I understand it's an App object, and the tick (no idea what it's called; this is starting to feel like a fracture mechanics lecture) I know has to do with ownership. It's tough to see how there are two subtypes in App<> when the assignment of app has ten functions that assign attributes. I can certainly READ what is being assigned to the App object. I wouldn't be able to WRITE any of this so far. Unimportant, it's not the meat and potatoes of ripgrep.
Now I'm scrolling, looking for something cool to analyze and run across Vec<&'static str>. Okay, I thought tick was ownership, but I also thought ampersand was ownership-related. Maybe one is mutability? (This is like knowing how to play music really well but now learning a totally foreign instrument.)
Skimming, it looks like this whole file is the argc/argv parser. I'll look for something interesting in main.rs, search.rs, and subject.rs (the last because it's an unusual name).
struct Config {
strip_dot_prefix: bool,
}
Well. I can read that! Next line... impl Default for Config {
...
...not that. It's probably something like a class method.As I'm reading through, it feels like a LOT of kicking the can down the road and verbosity. There's a function binary_detection_explicit(self, detection) that just assigns detection to self.config.binary_explicit and returns self. binary_detection_implicit() does basically the same with a different assignment member. getters and setters, roadblocking readability since the dawn of computer science... (a few lines later, the function has_match() returns the value of has_match. ugh. This is why I prefer crudely written C to textbook C++.)
I see .unwrap() in a line. This tripped me up during the tutorial; still no idea what it does. Sure I can look it up, but there are a hundred other terms to learn: unwind, map, Result (OH! The two App return types are probably Ok and Err ... maybe?), convert, concat, const, continue, ...
subject.rs, btw, can probably be written in three lines of really dense Python or ten lines of really well-written Python with a few other lines of Doxygen. Instead, it's about 90 lines of Rust with another 50 lines of comments.
Finally, I find something noteworthy.
fn search(...) ...
fn iter(...) ...
for subject in subjects {
searched = true;
let search_result = match searcher.search(&subject) {
....
This is all extremely readable and just feels like a standard queue in any language. But then there are lines like: if let Some(ref mut stats) = stats {
*stats += search_result.stats().unwrap();
}
I give up. Are you assigning the variable stats to itself? by reference but mutable? If Rust doesn't have pointers, what is *stats? unwrap() is no longer the most confusing part of this.-----
Postface, I'm originally a mechanical engineer who eventually got roped into writing driver software, so C is my comfort zone and I don't need anything much more complicated than "set bits here, read registers, use a 40-year-old communication protocol, handle errors".
There's simply no easy analog between Rust and Python ... or Rust and C ... or Rust and SQL ... or Rust and PRACTICE ... or Rust and any other language I've learned. I understand a lot of the CWE Top 25 software errors are mitigated by Rust and it's not just a theoretically correct but unusable language, but there hasn't been a strong reason to learn it, and the learning curve is made steeper by preconceived notions of every keyword.
-----
I forgot to compare with grep.c
Extremely readable. I know right away which part is args, where memory allocation happens, where file handling occurs, and then the "hard part"---where the magic happens---is the last page on my monitor. I can just stare at that and mentally deconstruct until pieces fall into place... Look up regcomp()? check. Look up grep_tree()? check. Read the kernel.org discussion on why grep_tree() was written and how it relates to ensure_full_index(), which explains some of the other variables.
The whole thing sits nicely in a few pages with terse but clear comments (unlike this post) and looks familiar even though I've never seen the source before.
-----
Last edit. I tried just now to refresh on .unwrap(). https://doc.rust-lang.org/rust-by-example/error/option_unwra...
Only because of the comments did I realize that calling drink.unwrap() will panic (throw an error?) if that argument is empty. So, unwrap is just the "if (... == nullptr) { return ...; }" of Rust, it seems.
But it's somehow an alternative to .expect() and has its own alternatives, unwrap_or/unwrap_or_else/unwrap_or_default, and it also seems optional. And my time in the rabbit hole is over; my children need to go to bed.
comment 3y ago · link · parent
Beginners, count your blessings. You don't need to unlearn other languages before learning Rust.
I sincerely believe the only keywords common to Rust and C are a few control flow keywords (for, if, while; but not switch, goto, or do-while) and "bool"---the latter only because of C99 and stdbool.h
comment 3y ago · link · parent
Firefox still---after years in the bug tracker---does not attempt to offer HDR support on Linux or Windows. Edge's HDR implementation might be buggy but it exists. (The Z13 OLED has an HDR calibration available.)
Chromium seemed to always have codec issues when I was using it. (not a hypochondriac, there are countless threads online with the same complaint)
So... It's either Firefox (poorly supported on this platform), something Chrome-based, or something simply poorly supported like the GNOME browser. (Aside, "Web" is possible THE worst name for an application.)
comment 3y ago · link · parent
The XPS 9370, for me, had ZERO problems. To the point where I wondered often why there aren't more Linux users. It felt like all of my previous Linux pain (especially a life chapter of running Linux on a Chromebook) had gone away.
I looked into a recent XPS but for a variety of reasons (keyboard layout availability in Europe, Michael Dell's political beliefs, wanting to switch away from Ubuntu's snaps and UX, reports of hardware issues on Reddit) I decided to try out "the other" major laptop brand with Linux offerings. Maybe I just got lucky with the last laptop?
Forcing a BIOS reset and installing Windows made enough problems go away that I now just run Fedora Remix as a WSL distribution. Annoyingly, the thing gets hotter than the XPS and hurts my eyes at night. The Z13 with Linux looked so good on paper, now it's more of a paperweight than anything unless I'm traveling.
Also... I wonder to this day if I'm the only Z13 owner who has two separate onboard mic sensitivities (one stereo channel is much more sensitive to nearby sound than the other and has an unusually high DC offset, which simply shouldn't exist on ANY microphone) plus the microphone on my left shows up in Audacity as the right channel (and, of course, vice versa).
comment 3y ago · link · parent
^WheelDown::
{
return
}
^WheelUp::
{
return
}
(this possibly needs A_MaxHotkeysPerInterval := 2000 )-----
<Caps> + a = ä.
<Caps> + <Shift> + a = Ä.
... and so on with all the German letters and currency symbol.
As a bonus, <Caps> on its own is mapped to "find" (Ctrl + F)
and <Caps> + f runs Send "{Space}datemodified:this year -kind:=folder", for when you have a lot of historical documents and want to get quickly on with the most recent using Microsoft's bafflingly stupid search operators. (Caveat, you have to switch to "last year" in January.)
comment 3y ago · link · parent
// test if we need a<<8|b
// or (a<<8)|b
// or ((int)a<<8)|b
// or (((int)a)<<8)|b
#include <cstdio>
#include <cstdint>
int main() { uint8_t a = 2; uint8_t b = 38; printf("%d\n", a<<8|b); }
More than half of the time is the uninteresting parts: writing the includes, creating a temp file, exiting to compile, forgetting a parenthesis, reediting and resaving, compiling again, running, deleting...In a REPL---particularly one with stdio/stdlib included by default---this would take 30 seconds but instead takes 3 or 4 minutes. It's not much, but tight feedback loops really, really keep you in a great mental state.
comment 3y ago · link · parent
I could see a strong use for things like multithreading, profiling, seeing a list of variables/values that are in-scope at a breakpoint. The more complex the software, the more useful...
The last time I needed a software debugger, a tool I was using would communicate with another by sending its PID as an ID. Problem? The tool thought the PID fit in a 16-bit, so it was sending a totally bogus number. I probably would have found this eventually, but with the debugger, it was as easy as "Why is the sent PID 39283 instead of 170355?" This only occurs after Windows has been on for several weeks and enough conhost/svchost/wslhost processes push new PIDs above 65535.
Humorously, such a bug goes away when you "turn the PC off and on again"
-----
Hardware debuggers (for microcontrollers) often have a whole host of benefits that are immediately obvious once you involve any physical I/O. Also, they're vital for things like event logging (for Arm, PMU events flag for cache misses, branch events, operation stalls, and much more) or seeing what's happening with an off-chip device, peripheral, other cores, anything to do with watchdogs, etc.
Writing something like impact failure handlers for a drive head controller for a hard drive, you'll want to be able to set an external trigger as soon as the failure is initiated, connect that to your debugger via one of its trigger-detecting inputs, and then you can capture the real-time data and execution traces and move back to the exact moment the failure occurred, how your variables changed, and what exactly the failure handler did to ensure the drive head attempted to park as soon as possible. In short, this is not printf-able, but it is also an extreme example.
comment 3y ago · link · parent
I just wish the Tailwind community (and those from other big-ass CSS frameworks) would internalize this concept. It feels so unintuitive to have your compiled HTML just element after element of class="lg:block fixed inset-0 top-[3.8125rem] drop-shadow-md justify-center hunter2-blue overflow-hidden pointer-events-none"
...especially when elements like <p> have the exact same giant class definition throughout an entire page.
comment 3y ago · link · parent
One rule is duplicated (a:visited) where it seems it should refer to a specific class (.hnmore a:visited):
a:link { color:#000000; text-decoration:none; }
a:visited { color:#828282; text-decoration:none; }
...
.subtext a:link, .subtext a:visited { color:#828282; }
.subtext a:hover { text-decoration:underline; }
.comhead a:link, .subtext a:visited { color:#828282; }
.comhead a:hover { text-decoration:underline; }
.hnmore a:link, a:visited { color:#828282; }
.hnmore { text-decoration:underline; }
Some lines don't have a trailing semicolon while the majority do. 0 probably doesn't need units. ".votelinks.nosee div.votearrow.rotate180" could just have one class rather than this nested thing.The single-pixel gif as a spacer, that takes my mind back to Geocities.
Sums up software pretty well. If it works, move on to the next thing. No need to get lost in the details that a tiny handful of people see.
comment 3y ago · link · parent
The bitcoin theft incident.
The presumed genesis of the attack is as follows: Bitcoin operates a public database of all transactions, the block chain. Each transaction is cryptographically signed by its initiator using the ECDSA scheme. Creating ECDSA signatures requires a per-transaction nonce. Partial predictability of nonces allows for one class of attacks, but using the same nonce for two transactions signed by the same key---which is what probably happened---constitutes a catastrophic security failure. Anyone can easily identify this case from the information recorded in the block chain, reconstruct the victim’s private key, and divert their money to a bitcoin address of choice. No intrusion into the victim’s system is necessary. A loss of seed entropy in the PRNG used for generating nonces increases the probability of the breach.
This ultimately caused Google to replace the Android PRNG, which was only providing 40% of the requested entropy for this particular use.
-----
I also recall someone had discovered an online poker service's shuffle algorithm was something common (maybe Fisher-Yates?) based on java.util.Random with system time as a seed. Once you see your own hand and part of the board, you get a fairly accurate idea of what could be in someone else's hand from the small-ish sample of possible deals around system time.
comment 3y ago · link · parent
Windows 10 + WSL
I thought an AMD + Radeon laptop would be a great improvement. Evidently I have the Reverse Midas Touch. Also garbage. Sadly, FULL hardware/peripheral support requires Windows or Mac, happiness everywhere else dictates Linux, and WSL delivers both (plus WebGPU, which is another aspect of Firefox/Linux that is perplexing and half-baked).
On both computers, X was a dramatic improvement over Wayland: proper color support (i.e. parts of the GIMP UI wouldn't turn magenta or half-transparent, you could enable HDR in Chrome), no extreme keyboard lag, all my Java binaries work without requiring cryptic flags, I didn't have to compile my own drivers from a guy named ElFarto, I could finally forget the difference between AV1 and VP9 and whichever gstreamer package lets you watch video again...
comment 3y ago · link · parent
It is recommended at work now, where I also can use "the old way" which is a series of Makefiles. I've never had a problem with the Makefiles, but they've been hand-tuned for a few decades, and errors would be reported immediately by the build server. They check if you have the right compilers and then just work. Contrast this with Docker, where you always have the right compilers and they only work sometimes.
While using Docker, if even one source file changes while the compilation is happening, the VM will simply hang and refuse to compile or accept any break keystroke. Outside of Docker, a file change sometimes works without error and sometimes you'll cause a minor problem that a new iteration of "make <whatever>" fixes in a few seconds. Worst case? "make clean", "make <whatever>", no reboot required.
After force quitting the Docker-based build, I try "machine stop" and "machine start" but often encounter errors and need to reboot my machine and/or reinstall Docker, such as this gem from last week, "No connection could be made because the target machine actively refused it."
I don't know if Docker has an equivalent to "make extraclean" or "make distclean" or "sudo cut the bullshit && let me use you again", so I'm already uncomfortable restarting a build after rebooting/reinstalling. (That you need to manually delete container directories after uninstalling is also troubling.) I know some data are stored in the container in a mixed-persistence way that uses the existing filesystem. It's confusing to me why some generated output (.pdb, .exe, .dll) are accessible outside the container while others (.o) are evidently not used if you decide later to rebuild without Docker. Thus, the difference when switching is often recompiling 5 files in a few seconds vs 500+ in a few minutes, so there's a short-term incentive to try to keep using Docker, where I then waste time trying to solve Docker instead of just recompiling with the old method. Any semblance of "Flow" I have after getting a Docker error gets annihilated.
If our local container server goes down (it's not often but has happened), I am unable to build because some of our dependencies aren't FOSS/widely available.
I've had issues related to services, prerequisites, permissions, mounts, certificates, massive network login delays... When I hear the constant praise for containers, it gives me pangs of imposter syndrome, because my experience has been awful and mentally taxing. I find I'm constantly fixing tools instead of using them.
I can't necessarily blame Docker, but twice in the past 3 years I've needed to install a fresh OS within a week after installing it because of the problems above.
Docker's main selling point? It fixes a problem we don't really have. Every developer at my company has essentially the same computer---an overpowered Ryzen/Quadro combo in a black tower with a small collection of preinstalled essentials like MSVC bintools, VCS software, network drives preconfigured---unless they specifically request another for build purposes, i.e. Mac or Sun. In the latter case, that developer (or small group of developers) is in charge of builds on that host OS. In the one place it matters, we have one version of a compiler expected in a specific directory, and this is well-documented and changes once every few years.
It's possible I completely misunderstand Docker or have a misconfigured system (whatever THAT means, I thought the whole point was to eliminate problems caused by local customizations), but for anyone to tout it as fool-proof would mean they have severely underestimated the technical (in)abilities of fools.
Docker, to me, often feels like bringing in and using a CNC machine when all I usually need is a sharpening stone and chisel.
-----
Also, I would be quite uncomfortable using GitHub Actions to compile C for a microcontroller. There's simply too long of a delay between changing a config YAML and getting an error, fixing it, waiting for the next error. Plus, despite the "low overhead" of Docker, if you do this long enough on GitHub (especially with a non-Linux host OS) you will run into server fees.
And after you set up a GitHub Action, are you writing in VS Code, waiting for the remote computer to compile, downloading the artifact, syncing that with VS Code so you can debug, flashing to the target with your own set of (locally installed) tools, and finally debugging?
Contrast that with a local install... Edit. Save. "make", "make flash", gdb. In 20% of the time, with no server costs.
comment 3y ago · link · parent
One of my favorite professors came in only on Fridays (except when the department would meet). They met with the research group, taught, had office hours, and then went home. I don't think they did nothing the other 6 days, but they also never sacrificed mental health for the sake of appearing busy.
comment 3y ago · link · parent
once you've let the thick wire settle back to room temperature---here's the cool part---quickly force it straight again and it gets suddenly very cold at the site where the bend was.
nitinol is neat
comment 3y ago · link · parent
(short but exact comments, inline testing, good function and variable naming, overall good use but not overuse of the standard library, functions very rarely more than a dozen lines, generally understandable code)
comment 3y ago · link · parent
header, *records = [row.strip().split(',') for row in open(filename).readlines()]
but then you need a way to parse the records, which could be Template() from the string library or something like... type_record = lambda r : (r[0], int(r[1]), float(r[2]))
At this point, the two no longer mesh well, unless you would be able to unpack into a function/generator/lambda rather than into a variable. (I don't know but my naive attempts and quick SO search were unfruitful.) Also, you're potentially giving up benefits of the CSV reader. Plus, as others have clarified, brevity does not equal readability or relative lack of bugs:In the course example, it's reasonably easy to add some try blocks/error handling/default values while assigning records, giving you the chance to salvage valid rows without affecting speed or readability. In fact, error handling would be a necessity if that CSV file is externally accessible. Contrast that with my two lines, where there's not an elegant way to handle a bad row or escaped comma or missing file or virtually any other surprise.
Anything else I can think of off-hand (defaultdict, UserList, "if not portfolio:") has the same initialization step, endures some performance degradation, is more fragile, and/or is needlessly unreadable, like this lump of coal:
portfolio = [record] if 'portfolio' not in globals() else portfolio + [record]
So... your technique and generators. Those are safe-ish, readable, relatively concise, etc.comment 3y ago · link · parent
Illegal? yes. Immoral? I'm not so sure.
Customs is ridiculous. DHL tacks on a 6 Euro fee if VAT isn't prepaid. Sellers often list the RRP instead of the paid price. (Newsflash: if I payed less than RRP, that was the market price when I bought it, so that should be the price listed on the CN 23!)
I paid more than twice what I should have on the last package I got from the U.S. It was on sale for 30% off, but the seller listed the RRP, which, plus delivery costs, put it over the threshold for adding customs fees. Adding on the post office's fee, it was 56 or 58 euros rather than 24 or 25 had they simply prepaid EU VAT on the charged amount. All this I know, because I also bought their competitor's product for essentially the same price, but the competitor (admitted, a much larger business) had a global delivery partner to handle the shipping and taxes.
I'd get a metal Ulmia or a KUNZ-plus if they didn't require work getting them true and sharp. I'd get a knockoff if the knockoff brands start to innovate and introduce new designs. With Veritas, Lie Nielsen, and Clifton, I know I'm supporting innovative small businesses and owning functional art that maintains its resale value after decades of heavy use.
comment 3y ago · link · parent
Furthermore, I'm not a fan of your personal beef with Jake and think it's over the line to accuse self promotion when he's not selling a book or service or anything other than seemingly pushing an opinion.
jaffathecake has posted, on average, once per year for the past two years. Going back to his account beginning: it's five times per year.
He posts topics that are engaging (over 60 points per post for the past 30 posts, only 10 of these posts were ignored) as well as technical and usually interesting. He then has a discussion---there are certainly other blog posters who simply post and leave. I much prefer this largely posting of one's own work to people posting tangentially relevant (at best) articles from Politico or The Atlantic. Other people regularly link his posts, confirming that he has an audience on HN. He's not even reposting his old articles or posting three times in a week when a topic doesn't "catch" on the first two attempts like MANY of the karma-heavy serial posters on HN.
His comment style (aka stubbornness) probably comes from his own development experience and he doesn't see the perspective of people writing simple "gg=G" auto-indent algorithms using Python in a new world of custom HTML elements (web components) or writing regex to quickly add a property like aria-level to every tag that can contain. These might be inefficient and contrived use-cases, and he'd probably have a leg to stand on that the trailing slash isn't necessary in those two cases, and I'd like to see what that response looks like, because I tend to oscillate between using an SSG (which I despise because I find myself picking apart i18n bugs across multiple files---a task I'm doing today) and writing HTML by hand (where I find myself needing to bulk-edit with vim or sed). This---the complexity of most frameworks vs keeping it all in your head while learning why "strong" is now preferred over "b" and trying to hand-write responsive CSS---is the modern reality that is making larger-scale web development more inaccessible for tech-half-savvy folks.
I fail to see that he's selling anything. I don't see ads anywhere on his blog. He even rejects recruiters and advertising offers on his front page. If this whole blog of his is just a ploy to get people onto his other (potentially monetized) social media, he is not pushy about it AT ALL.
comment 3y ago · link · parent
https://raw.githubusercontent.com/PennRobotics/permalink/mai...
Since the same UUID in the manifest applies to Windows 11 and Windows 10, I'm willing to bet this would look a lot like the Windows 11 version of notepad.exe when compiled on a Windows 11 machine.
comment 3y ago · link · parent
(I realized how widespread these parts are online after my toddlers got a Duplo-Brio gift that was purchased from an online shop but was obviously printed.)
comment 3y ago · link · parent
It reminds me of my former neighbor's dating strategy. A few times I used Python and the HN API because I was interested in the average karma per submission for top users and whether it matches my own opinion about their post quality. It led me to believe maybe a good metric for limiting the number of submissions someone makes: daily submissions allowed = average karma per submission (once you've reached 20 or 100 submissions)
It's not something I can relate to---why people do this shotgun thing; shoving a mound of potentially interesting (and often not self-written) articles in hope that two or three land on the front page. The karma doesn't do anything except give you validation that your contributions "mattered", but if you repost someone else's work (or even your own from the past) you're basically getting validation that other people might care about this thing you care about... which feels empty, to me.
I personally can't develop something technical and interesting more than once per week, and then I doubt how many users want to read about my really obscure and often futile interests (automating cloud publishing of ABC files, trying/failing disassembling an obscure DOS game, random SCAD files for one-off minor life improvements, buggy Python libraries for poker/tailoring/instrument tuning, learning just enough to almost push a stylus driver for two unpopular Linux laptops)
Mostly, I like reading the articles by people who do something technically cool and new and put a lot of effort diving into that thing and sharing its secrets, like this CAN injection post. The expectation is that those users can only post a few times a month unless doing cool stuff and writing about it is their full-time passion/job. Another expectation is that there are enough of these people that the front page can stay full with technically cool/new posts.
The third---and by far, the hardest---expectation is that great* (by my own flawed definition) posts need to be promoted reliably and without bias from /newest to / while also working to reject only-fanboy-/self-voted content or poor quality wikipedia links and seventh "own repost" in four years and New Yorker articles about hip-hop...
I used to flag bullshit articles right away, but they arrive like waves on the beach, and I've learned to filter past the stuff I dislike rather than bother losing some unseen privilege because I get put on a "user who flags too much for bad reasons" list.
To elaborate my skimming: in this moment, there are two reasonably popular but reasonably "not so techy" Wikipedia articles in the front page 30. There are two non-tech (historical) posts---one by a hit-or-miss "often poster" and another by someone who basically only posts non-tech/historical subjects---although in this case, once every two weeks. Five users I recognize as "I post all the damn time" users, although I only consider one of those in the "I post all the damn time and it's annoying" camp. I instantly recognize one repost, but it's one I would find interesting if I saw it for the first time. The majority is stuff I find appropriate for HN, and a minority of that is stuff I personally find interesting. If I get two or three decent articles on the front page and one from /newest, that's still 20 minutes of content that I enjoy, and the HN status quo gives me this.
"GPT, express all the above thoughts and sentiments but only using 30% of the characters I used and with far fewer personal pronouns."