Better HN
topnewbestaskshowjobs
Log inSign up

codebje

1,356 karma · joined Jun 19, 2017 (9y ago) · 591 submissions

Submissions

comment 3y ago · link · parent

Star Wars is pretty dystopian in every era shown in the movies. Even at the height of the Galactic Republic large areas of the outer rim have people living in poverty and outright slavery. Coruscant appears nice, but a little below the surface criminal gangs are running the place with most of the planet's population never even seeing sunlight.

Plus the powerful elite tapped into the discontent that they'd created in order to further their own power, then crushed the useful idiots who rebelled against the oppression and doubled down with more oppression.

comment 3y ago · link · parent

You've seen the scope output for bounces: the signal will often go completely from one extreme to the other, as well as a little bit of noise just after a change. A switch might bounce a hundred times, rail to rail, taking 5ms or more to settle. A typical switch probably only bounces 1-10 times over 1-2ms, but unless you plan to test every switch and throw out the worst ones you should plan for the worst.

A capacitor resists change in voltage. Where a switch's change on the oscilloscope usually looks like a steep cliff, adding a capacitor will introduce a curve as the voltage drops. The size of the curve depends on both the capacitance _and_ the resistance between ground and the capacitor: simply adding a capacitor won't give you much of a curve because there'll be very little resistance. You also need to add a resistor to make an RC network.

To handle the worst of switches you want an RC value somewhere around 10ms. What you choose for R and C depends on any other constraints you might have, like power consumption or capacitor size.

Because the RC network slows the transition time a lot you need a Schmitt trigger to convert the slowly curving voltage change into a nice sharp input signal change without allowing noise to ruin everything.

There are other ways to deal with bounces in hardware, too: you can convert the switch's on/off signal into a pulse using a monostable circuit (eg, a 555), you can use a dedicated debounce IC, you can use a flip flop with a SPDT switch, you could blow $50 on a Hall effect switch and use an ADC.

Or you can deal with it in software, which is popular because it's typically easier to find space in a ROM than it is to find space for discrete components on a PCB.

comment 3y ago · link · parent

That place has nice beer, but no atmosphere.

comment 3y ago · link · parent

> Could our computers handle it?

It's been a very long time since computers were anything other than binary, and unless quantum computing takes a, haha, quantum leap forward it will be a very long time yet until they're doing anything else.

But they can handle converting to and from this numeral system for the few humans who find it more natural to work with just fine.

comment 3y ago · link · parent

Lua is super common because it's super easy to embed into a C(++) project.

comment 3y ago · link · parent

XMPP (née Jabber) isn't a broadcast messaging platform like Twitter or Mastodon, it's a one-on-one or small group instant messaging protocol. It absolutely failed to take off as a broadly decentralised instant messaging service, for a bunch of reasons, but it absolutely succeeded in becoming a widely used instant messaging protocol, at least for a while.

Jabber was born in 1998, in a world where there was a handful of centralised desktop instant messaging apps that didn't interoperate at all - ICQ and AIM dominated, but there were plenty of others around too. Most of us ran multiple apps at once, or tried to get clients that could connect to multiple services, but this was complicated by proprietary and frequently changing protocols.

A decentralised, federated, and open protocol that let users connect to all other users was a great idea… for users. But it didn't do anything for the behemoths rapidly gaining users in their proprietary centralised systems, and it didn't do anything for ISPs who'd just have to run, and support, another service. Early clients and servers weren't as straightforward as downloading a desktop program from Tucows and running it, and in the space of technically savvy people running a system built on open standards there was already a well established (and heavily fractured!) IRC.

XMPP's standardisation in the IETF didn't really help it. While the IETF isn't quite as slow as more traditional standards bodies it's definitely nowhere near as fast as centralised companies with only one client implementation to care about. As the war for eyeballs heated up, instant messaging apps rapidly added features like sharing images (crazy! over _dial-up_?) or emojis (before they were called emojis!) and XMPP simply did not keep up.

Nevertheless, XMPP was the basis of iChat (or at least, some versions of it) until iChat was killed in 2011, and the basis of Google Talk until that was killed in 2013. It wasn't too uncommon for corporate internal chat platforms to be using XMPP in one form or another - Cisco still have a product today called Cisco Jabber. But the main thing all of these systems had in common was they absolutely sucked at federating with each other. Theoretically Google Talk supported it, but your corporate system probably didn't. iChat notionally might've but as far as I recall it had so many proprietary extensions and missing standard features that it just wasn't feasible to federate. XMPP did pretty well for a stretch being the underlying protocol for a bunch of proprietary, centralised, and siloed chat systems.

In the end mobile phones killed instant messaging platforms. In the 90s most of us didn't have phones, but at the start of the century that rapidly changed and suddenly we all had the same instant messaging platform right in our hands: SMS. Sure, it was never built for heavy use, and mobile companies often charged per message (50c per text in Australia in the early 2000s), but it was _there_ and everyone was on it, and in just a few years desktop instant messaging died off. XMPP never had a chance.

Smartphones, of course, re-introduced the hot mess of a dozen competing instant messaging platforms with different parts of your social network on different ones, all centralised, all proprietary.

comment 3y ago · link · parent

That's a great example of knowing exactly what ??? means: the program is misbehaving and should terminate.

It's dead in the current call stack, but over time programs change and that is how errors creep in. If it's a precondition that _baz_ is in a particular range for the function to behave, why not check that in an assert and save yourself or a future programmer a ton of stress trying to work out why some unrelated part of the code blew up when they made what seemed like a simple change nine layers up the call stack?

There's no runtime cost to an assert in production code, but it makes your intent clear to both the compiler and other humans.

comment 3y ago · link · parent

If you don't know what ??? should be, your code's going to misbehave in production - at best crashing, at worst causing data corruption or an exploitable vulnerability.

If "???" is just "foo = INT_MIN;" clang will optimise it all down to a single addition (see https://godbolt.org/z/K1ee8h3TM). If it's always "foo = INT_MIN;" across all of your code you can just use "-fwrapv" to override the C standard and define signed addition as two's complement wrapping.

GCC will ignore the possibility of overflow in signed addition if you don't do anything special (e.g. https://godbolt.org/z/Pc76c5E9z).

You can use "-ftrapv" (or "-fsanitize-undefined-trap-on-error -fsanitize=signed-integer-overflow") to make bigger, slower, safer code that fails fast on unexpected overflows across the board.

You can do the rather unergonomic "__builtin_add_overflow(bar, 1, &foo);" to tell the (GCC or clang, at least) compiler "???" is two's complement wrapping. You can do the cheeky, non-portable, but predictable on the same compiler and platform "int foo = bar + 1L;" to do the same thing. Combine these with "-ftrapv" and you'll get code that short-circuit blows up for unchecked unsigned overflow with the opportunity to produce faster code where you either are damn sure it can't overflow or where you want two's complement wrapping on overflow.

If it's not in a tight inner loop avoiding a check is premature optimisation - if you're consuming I/O and doing lightweight processing on it, an overflow flag test on signed additions will not make a measurable performance difference, nor will it blow out your binary size unreasonably.

IMO it's not a red herring to have signed integer overflow flagged as a potential error. The error is the failure to have an answer for "???".

comment 3y ago · link · parent

> I have noticed this when trying to get it to generate some code, it was clearly using considerably old versions.

I have noticed the same thing when trying to use junior devs to generate some code, usually correlating with how old the most popular Stack Overflow question on the subject is.

comment 3y ago · link · parent

I have been on and off writing an emulator for the eZ80 CPU. This CPU has two addressing modes, Z80 mode in which it's effectively an 8-bit processor with a 16-bit address space, and ADL (Address Data Long) mode in which it has a 24-bit address space. There is a CPU control bit 'MADL' (Mixed ADL) for mixed-mode applications; when set, using certain prefixed opcodes will switch modes during call and return.

A Z80 routine can call outside of its 16-bit address space with 'CALL.IL'. This pushes the 16-bit return address onto the 16-bit stack, switches to 24-bit mode, and pushes the magic 'return to 16-bit mode' number to the 24-bit stack. However, it's not clear from the manuals or datasheets what happens if you use the prefixed 'CALL.IL' opcode sequence when the 'MADL' bit is reset.

I asked ChatGPT, because this is something that Google searching hasn't yielded answers for. It had this to say:

"The MADL bit (short for Memory Access During Interrupts Low) is a flag in the Interrupt Control Register that determines whether or not interrupt service routines (ISRs) can access low memory (addresses 0000h-3FFFh) during interrupts."

Plus some more stuff building on that, on CALL.IL being about ISRs, and about low memory. All of it is completely, fundamentally wrong. I did a handful of rounds of trying to steer it to a more correct answer but it continued to get additional basic facts wrong and would lean back to earlier incorrect facts as others conflicted with its answers.

I asked it another question I have, this time about the UART on the CPU. There is a Receive Buffer Register (UARTx_RBR) that contains the head of the receive FIFO. The documentation does not make it clear what is in the RBR if the FIFO is empty, so I asked ChatGPT. It told me a very plausible answer, the one I suspect myself, which is that it'll keep returning the same value until new data is available. But then it went on to tell me this is called receiver overrun, and described how an overrun occurs, including noting that it happens when the FIFO is full. And we went round in circles on this for a little while.

ChatGPT is a major step forwards in our post-truth existence: its answers are an amalgam of the most frequently repeated views on a topic, not those with stronger reasoning or more effective evidence to support. If there is little or no source data on a topic (as would be the case with my very specific questions on a rarely used processor) LLMs are (presently?) unable to detect that they are responding to a topic with limited contextual information and tailor their responses accordingly, and instead confidently provide utter nonsense.

I trust ChatGPT to do things that LLMs are good at, though: if I give it some bullet points and some style guidance it can give me written paragraphs. If I ask it to rephrase a well known song in the style of some modern artist I'll get something back that's pretty plausible. It can give me some starting points for learning more about some well known topic, even.

I would definitely not trust it _at all_ to give me something factual like part numbers of uncommon ICs, because LLMs cannot distinguish between fact and fiction, not in what they ingest, and not in what they produce.

comment 3y ago · link · parent

The only thing that got hacked to pieces more than the English peasantry during the middle ages was the English language.

comment 3y ago · link · parent

It only took 200 years for 200 of those 260 languages to be lost or brought to the edge of extinction. It's at least plausible and to me quite believable that the arrival of a group with a technological advantage 4,000 years ago could have had a substantial impact on the existing languages.

The same set of languages definitely will not have survived for 60,000 years. Tribes come and go, merge and split. Outside influences bring in new words and grammatical structures. Oral tradition is a low fidelity carrier of language and culture, and easily accommodates change in language.

comment 3y ago · link · parent

It looks pretty typical for BASIC of the late 70s to me.

You wouldn't want to waste characters on commenting code: machines of that era would have only a few KB of RAM, as low as 1K. For the same reason you don't want to waste characters on long, meaningful variable names or on well spaced code. Multiple statements per line isn't to save print space, it's to save RAM.

Meanwhile, the program's pretty well structured for such a short bit of BASIC: subroutines start at multiples of 100, for example, and each subroutine starts and ends clearly, no shenanigans like jumping from the middle of one sub to another, no multiple exit points for subs, all as linear as it can be. The use of IF is limited to skipping forward a short way to conditionally execute a line or two only. GOTO only exists in those IF statements.

I'd have been happy to have written code like this, back then.

I am pretty sure that my uncle ran this exact program on his computer and printed out biorhythms on listing paper, in the mid 80s.

comment 3y ago · link · parent

Institutions often reward publication in more impactful journals, and careers are built on your publication history.

Journals also often require that you assign copyright to them and restrict your ability to publish in more accessible places.

comment 3y ago · link · parent

There is so much to dig into for one short article. So much. Too much for an HN comment, I think. A few bullet points:

- It's not an event sourced system, it's a relational system with an absolutely terrible audit log. - The audit log is (was?) serialised and blocking for every transaction, okay for low volume and low latency transactions. - 30 minute transactions!? That is NOT low latency. That needs engineering to manage contention. - The last updated event information is updated in a transaction and definitionally is always the most recent event… what's it actually for? - The solution is exactly equivalent to a boolean "is_applied" column on the event table… and is still always set "true" inside a transaction.

> That sounds like a recipe for disaster when your replay code and update code are not actually in sync?

It reads like their replay code is their update code, but they have absolutely no confidence that their event history is complete and consistent ("A lot of things can go wrong with a large history, foreign keys, exceptions, serialization mismatches, events out of order etc.") so it's unlikely they'll ever risk replaying events.

The bit that I think has the most interest to consider, though, is the granularity of events. The article refers to database transactions as a monoid, which is to be expected since the application's architecture is built around database transactions and not events, but events can also be treated as a monoid. Making events extremely low level (eg, https://vvvvalvalval.github.io/posts/2018-11-12-datomic-even...) provides a ton of flexibility but absolutely needs the higher level semantic information to be explicitly written as well, else a significant portion of the value of event sourcing is lost. Simply recording a transaction ID (as the github account linked to the article does) won't help much as business requirements change over time, exact dates of changes become fuzzy and forgotten, and inferred meanings drift. Event sourcing works best when it's complete and explicit.

comment 3y ago · link · parent

Yes, that's true - I may have to reconsider which one I think got it the most wrong :-)

comment 3y ago · link · parent

You don't need to expunge c89 from gcc for progress to have happened - we've got c99 and c11 and whatever c17 is or isn't already there.

Effectively, however, python2 and python3 are different languages. Since they're interpreted, there's now a problem with '#!/usr/bin/env python' in your script: which python version is being invoked? Which language version are modules targeting? It's a mess.

But the poster child for screwing up a language version upgrade is still Perl.

comment 3y ago · link · parent

I am interested in the convergence of AI-generated code and programs-as-proofs: can I work together with AI using a language with a highly expressive type system such that we co-develop a specification in types and properties, then co-develop the implementations that fit the specification.

It's not practical to do that sort of thing alone, as there's a lot of tedious nonsense involved. Maybe it will be more practical with an AI assistant.

Whether current AIs are more or less somewhat close to the basics of how humans might be approaching code writing is more of a philosophical point, but a "translation room" view of the human mind might on occasion make me feel like I'm just working off patterns from my data sets. :-)

comment 3y ago · link · parent

I don't think the halting problem's got anything to do with it, because I certainly also can't prove, in general, whether some code I have written halts or not either but that hasn't held me back from churning out vast quantities of text that, at first glance, might also resemble good code.

But I agree with your sentiment: to get AI to write the code you want, you will need an engineer to work with it.

I do expect that future AI code generation models will learn more about a specific code base over time, partially overcoming domain specific knowledge gaps.

comment 3y ago · link · parent

I'm very far from an expert in this field, sorry. PCM (and other resistive memories) are definitely still a thing, though - they've been used for in-memory computation, doing vector-matrix multiplications directly in the memory cells and thus saving massive amounts of die area over using separate CMOS logic, so they're probably going to replace on-die SRAM for some applications.

comment 3y ago · link · parent

Not really, no. For a start, I don't think NAND flash itself is an example of planned obsolescence: its main predecessor is spinning rust platters, which were notorious for sudden catastrophic failures. Spinning rust replaced, more or less, magnetic tape, which does have an effectively unlimited lifespan (it's more likely that you won't find a working tape reader than that you'll find properly stored tape is no longer readable) but is otherwise a terrible storage medium.

But more on point, this article's context is static ram on-die for a microcontroller or similar. One possible replacement for SRAM is magneto-resistive RAM (MRAM) - it's not quite as fast as SRAM but close enough for many applications, it's higher density than SRAM, so it'll take up less die space, and it's non-volatile so µCs can ditch the NOR flash often used for code storage.

One great thing about MRAM is that it has no write wearing: it has an effectively unlimited lifespan, without all the downsides of magnetic tape. I look forward to seeing it (or similar technologies) in microcontrollers in the future.

comment 3y ago · link · parent

One reason come to mind: Conway's law. If you have a monolithic team a monolithic server is usually a pretty good solution to a problem. If you have multiple teams you're likely to wind up with an architecture that lets them work more independently, leading to separate release schedules.

... which perhaps just shifts the question to "why do you need multiple independent teams and not just use a monolithic development team?"

comment 4y ago · link · parent

How does one make the leap from "a source available but otherwise proprietary license" to a copyleft license? As I understand the terms, perhaps in too limited a way, a proprietary license is never one in which others are free to build on the code or incorporate any part of it into their own works, and a source available proprietary license is just publishing source that no-one can use.

As for whether Copilot's morally wrong or not - I don't think copyright as a concept makes any sense at the level of the trivial, where Copilot _should_ be acting. If Copilot regularly reproduces sizeable portions of code from a single origin _without_ careful and deliberate guidance, I'd agree that there's a problem here. As I understand it though, that's not happening.

By its very nature of being published, code from OSS is funnelled into proprietary codebases by humans performing a similar task to Copilot - reading available code and using that to evolve an understanding of how to produce software. I like to think we do it at a deeper level than Copilot, but the general effect is the same: the code I write, like the words I write, are heavily influenced by all the code I've read over the years.

If I wind up using a few words from your comment, down the line, because some turn of phrase you used struck me as a good way to say something, do you think I've morally wronged you?

comment 4y ago · link · parent

I find your comment a bit perplexing, perhaps you can help me understand.

Why do you want to release code on GitHub with an oppressive license? What's the motivation for you, and what's the benefit for anyone else in it being released?

The size of code fragments being generated with these AI tools is, as far as I can tell, extremely small. Do you think you could even notice if your own implementation of sqrt, comments and all, wound up in Excel?

comment 4y ago · link · parent

> Banning a /24 doesn't have too much collateral damage.

Even at 128:1 CGNAT ratios a /24 has 32,768 potential users.

By comparison, a /56 has 256 potential users on a /64 each.

comment 4y ago · link · parent

Collateral damage is accepted for CGNAT, which is widespread already, and will be equally well accepted for v6 /56s (or /60s).

comment 4y ago · link · parent

The difference is typically between a static _public_ IPv4 address or a dynamic _private_ IPv4 address, and CGNAT sharing public IPv4 addresses across subscribers.

comment 4y ago · link · parent

If you're already doing base index addressing (eg, [SI + DI]) you're already using the ALU to compute your memory address, and it's not _that_ much extra wiring to have the ALU support either a constant power-of-two displacement or even a three-way addition; a constant displacement for a basic ripple adder is a XOR and an AND NOT, eg. The x86 family does three-way addition (and a shift) to support "[ESI] [EBX * scale + displacement]".

comment 4y ago · link · parent

Well, maybe, if the specific use case of 1-based arrays was all that got supported.

It'd be a pretty huge waste of processor design space to do that, though: if an HLL wants to support n-based arrays for n != 0 it can just store the base pointer with the initial index offset already applied.

Early 8-bit processors had a pretty poor set of addressing modes: you couldn't even expect [R1 + R2] let alone [R1 + R2 * scale + displacement], so random access into an array would be a multi-instruction task. By the time of the 80386 base scaled index addressing with displacement was in the CPU core, but it's not _free_ - there's an additional byte in the instruction encoding for the displacement, so even if the CPU computes the displacement with no additional clock cycles you'll have a latency cost for fetching the byte.

comment 4y ago · link · parent

Like TFA suggests, right at the end, this is where code review shines. Keeping documentation valuable is a discipline challenge, and we all fail from time to time at keeping ourselves disciplined. If you have team agreement on the level of documentation that gives good ROI for time spent maintaining it, you can rely on your team to help catch your slips just as they can rely on you to help catch theirs.

Using something like ADRs[0] can help provide the structure the team can look for when it comes to "why" documentation. I recommend a standardised README across projects. If it's "what" comments look for language tooling that will execute documented examples as test cases. If it's "how" then make sure there's value in it - do you have disaster recovery exercises, does your incident response team use your "how" documentation to triage issues, do stakeholders outside your development team get consulted on contextual changes in your application, etc.

[0]: https://brunoscheufler.com/blog/2020-07-04-documenting-desig...

1
111213
20