Better HN
topnewbestaskshowjobs
Log inSign up

codebje

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

Submissions

comment 6y ago · link · parent

If you wanted to be able to test your MS Paint clone, you might implement your drawing core without being dependent on a window existing. An off-the-cuff approach might be to have the core define a canvas interface with the rendering primitives it desires, and provide a suite of functions that will translate user input actions to canvas rendering primitives.

A purely functional approach would involve a core of functions taking in a current state and returning an updated state and a list of canvas actions to take.

Functions might include "select ellipse tool" and "set pen width to 5" and "click on canvas at point (3,15)" and return canvas primitives like "render ellipsis from (3,15) to (47,99) with stroke width 5, stroke colour black, and no fill".

Unit testing of the core should obviously be quite simple to do, being totally independent of the GUI system.

comment 6y ago · link · parent

Hemangioma in my case. I had an MRI but in the end it was a surgeon with the right experience looking at an earlier ultrasound that diagnosed it.

I had trouble believing he'd diagnosed it when he glanced at the ultrasound and calmly said what it was. Given I'd had medical practitioners send me for neurological studies to check it wasn't all in my head, suggest fusing my wrist to stop the pain, tell me there was nothing visible in X-ray, MRI, or the same ultrasound report the surgeon diagnosed me from... It seemed unlikely anyone could do an apparently simple diagnosis like that.

comment 6y ago · link · parent

I had pain and weakness in my right wrist for years, and also had many rounds of misdiagnosis.

It turned out to be a benign tumour. Surgery was my answer, but it's only a partial one. It's a soft tissue tumour, the surgeon didn't expect to get all of it, and it's growing back now. It's been about seven years, and I expect I'll need surgery again within seven more years to be able to do simple tasks like lift objects with that hand still.

Sometimes it's not diet - but it's like the old climate change joke. What if I switched to a better diet and a healthier lifestyle, for no good reason?

comment 6y ago · link · parent

Thanks, I'd forgotten the Gameboy wasn't actually a z80 and never knew about the master system!

comment 6y ago · link · parent

That would have been a specific machine built around the Z80. The Z80 CPU has a 16-bit address bus and can handle 64K of memory. It has an 8-bit I/O bus, but it was common for Z80-based machines to use memory-mapped I/O like the 6502.

Two very common machines from the era were the ZX spectrum and the TRS-80. But there were dozens - Kaypro, Osborne, MSX, the Nintendo Gameboy... the Z80 was used in lots of machines. Chips based on the Z80 are still used in embedded systems today.

I built a retro-computer this year using a Z180, which is a Z80 (minus undocumented behaviours) core with a handful of useful peripherals built in. They're still actively manufactured and sold.

comment 6y ago · link · parent

If you can, you should.

If you can't, it's (IMO) because you're stuck with the burden of having to write and maintain that code.

If it's an asset, why not just write more?

comment 6y ago · link · parent

I mean that source code comes with costs, often substantial, but has no direct benefits.

It's easy for us as developers to think that source code is valuable - but this leads to problems like never removing code "in case it's needed", or with an in-house dev team developing systems you could get off the shelf.

If code is an asset, then it makes a lot more sense to write stuff yourself: you not only get the artefact, you also get the source.

If it's a liability, then it makes a lot more sense to let someone else bear the costs of that liability, especially if they have economies of scale, except where you can't get your desired outcome other than writing code.

This is of course technically incorrect. It's perhaps more accurate to say that source code requires upkeep and is expensive to maintain. That tends to draw less interest and discussion, because it's "obvious." Except as an industry we're overall pretty lousy at paying the required upkeep on code.

comment 6y ago · link · parent

A company's codebase is a liability, not an asset - it needs to be maintained, and as you point out, it needs money spent on tooling and infrastructure to be most effective.

Unless you happen to be one of the very rare companies that sells source code and not built artefacts, your asset is the built artefact and your code is the expense you take on to get it.

Having less code to get the business outcome only makes sense when you see the code as a cost, not a thing of value itself.

comment 6y ago · link · parent

Type systems limit the set of programs accepted by the compiler. A sound type system will reject every bad program - but also may reject some good programs. Type systems therefore also will have escape hatches to let the programmer overrule the compiler.

Bad type systems need you to use the escape hatches frequently - you can't write much C without using casts.

I haven't yet used a language with no need at all for an escape hatch - but some languages need them far less often than others.

Java's type system is better than it was. The main places it still has weaknesses are around exceptions (you will need to wrap checked exceptions in runtime exceptions in places you'd have preferred to specify an exception type via generics, eg) and the occasional cast after an instance type check.

You can phrase good development practices in business terms: what are the risks to the business due to sloppy code? Are they greater than the risk of being slow to market?

Sloppy code has accumulating costs. A good type system can help greatly with refactoring to address those costs, but it cannot help with the attitude that those costs aren't real and don't need to be paid.

comment 6y ago · link · parent

Scott Meyer's "Magic 2.0" series is more or less this idea.

comment 6y ago · link · parent

Wouldn't that only show \exists x: A(x)? Or perhaps by free variable you mean one whose value isn't decidable - but that contradicts having chosen values in the origin comment.

comment 6y ago · link · parent

Could you explain that a little for me? Do you mean substituting a term to show a counter-example?

comment 6y ago · link · parent

The incorrect reading is that x and y are free. They're universally quantified, as you've said in your comment.

comment 6y ago · link · parent

How else could you combine infinite streams?

comment 6y ago · link · parent

Are you referring to the argument that Haskell's IO type is insufficiently granular to distinguish between something like erasing a disk and something like catching an async exception, or that the language's first-class feature set should be extended to things like async exceptions so they don't need to be part of "the rest of the universe" ?

comment 6y ago · link · parent

Nice read. I'm not familiar with Lucid, so invocations of "fby" and so forth went over my head, but finding that there's an abstraction available to encapsulate and explain a lot of behaviour in a consistent way is always a good win.

The "output monad" described is usually called the Writer monad - you can append to a log, but you can't do anything based on what was in it. It can be generalised from strings to any monoid - a domain that has an empty value and an associative concatenation function.

The IO monad, as another commenter said, is a kind of state monad where the state is something ineffable from within the computing environment: it's the state of the world outside the program. But there's no need to rush to trying to fit the IO monad to this model - we can start with the "reader monad".

An element of D* for the reader monad is a function from an element of some specified domain R to an element of D. The mapping from D to D* is a constant function that produces D no matter what the argument to the function in D* is. D's elements are functions from R to D* so the collapse is function composition and therefore associative. Likewise, f* from D* to E* is function composition, which composes, obeys the embedding of D into D* and since both collapse and embedding functions is function composition f* * (s')V == f* (s'V).

The reader monad is sometimes called the environment monad, because there's some environment (the value from R) that is available to all computation. The key thing it gives us for this article's model of monads is that elements of D* don't have to just be pairs, they can be functions.

Sort of combining the Reader and Writer monads gives us a monad where an element of D* is a function from an element of the domain S to a pair from (D, S). The embedding from D to D* is the function that copies its input state to its output pair. The collapse from D is composition with application. An element of D* * is a function S -> (D* , S), or S -> (S -> (D, S), S); apply the function in the pair to the state in the pair and you get S -> (D, S). D* * * is the further nesting of this structure, S -> (S -> (S -> (D, S), S), S). Evaluating this is associative: either way you will pass the initial state through each function in the same order to get the final output state. Embedding a function also satisfies the laws; effectively it will transform the final output D and leave the state S alone.

The collapsing of State to ensure its functions are always evaluated in the same order is how the IO monad provides sequentiality of effects. The state is "everything outside the program" - the user, the keyboard, the network, the operating system, even parts of the interpreter state that are not typically open to program inspection, perhaps allocations or bit-level representations.

An element of D* for the IO monad can read from the state of "everything outside", seeing whether the operating system has a character in its console input buffer perhaps. It can modify the state of "everything outside" by writing a character to the OS console buffer. And it preserves the order of these things because of how collapse is defined.

It also needs a magic interpreter that can provide the initial state of the world and maintain it as the program updates that state, along with magic primitives that can make changes to an ineffable "real world" state.

comment 6y ago · link · parent

I blog about my electronics project. It's public in that it's online and accessible but it is for me, both to ensure I think things through well enough to write them down coherently and to have a reference for decisions.

I blog my work activities on an internal wiki for similar reasons. Major decisions need to be gathered in project documentation but small decisions and daily challenges are good to have written down.

comment 6y ago · link · parent

"… or otherwise invent some other way to ensure the new refresh token is correctly received at the client before revoking the old."

These sorts of details will typically wind up in an implementation report document. It's rare that an IETF protocol specification document will attempt to pre-determine the solution to all such implementation details up front, and IMO, not good when they do.

In some contexts, it may be much better to require the application to re-obtain resource owner authorisation than to allow a replay of a refresh token. In others, it may be much better to avoid requiring resource owner authorisation. What you see as a bug, others would see as a critical feature.

comment 6y ago · link · parent

The halting problem is that there is no algorithm possible that can answer, for all programs and all inputs, whether that program with that input will halt.

Here is my program:

    def fool(input):
        while input:
            pass
The input given to the program is your answer as to whether it halts given that input.

That's the gist of the proof that the halting problem is unsolvable. Whatever the algorithm or method is used to answer the problem, you can take that method and "embed" it into the program to be verified, and invert the answer.

The halting program doesn't say you can't answer for many or even most programs and inputs, it just says there'll be at least one counter-example.

comment 6y ago · link · parent

I'll try to remember the attribution as well as the aphorism in future, thanks :-)

comment 6y ago · link · parent

Why not just have "a" return something containing "b"? In Python 3.8 for the brief syntax afforded by assignment expressions:

    def foo(o):
        if (b := o.a()) is not None:
            b()
Because the original interface indicates that all "o"s must know about the link between "a" and "b", there's no loss of generality, but now there's a statically inferable structure: "o" must support an "a" that returns None or a callable.

If you do a tiny modification to "def foo(o, a): ..." then this doesn't apply any more, and you're outside the realm of structural types and into the realm of dependent types, which means you must drink deeply of the static typing kool-aid and want to write type signatures that run the risk of being more complex than the code they describe.

(But I like to quote Conor McBride: "if you're not going to write types your type system has to be stupid enough a computer can do it", from https://www.youtube.com/watch?v=3U3lV5VPmOU&feature=youtu.be...).

comment 6y ago · link · parent

It also has silent type coercion, so it will happily promote your _Bool to an int, neatly voiding any benefits the type might have had to offer.

comment 6y ago · link · parent

I heard an aphorism once I've tried to live by since:

It is twice as hard to debug code as it is to write it. If you write code as clever as you can make it, you will never be able to debug it.

comment 6y ago · link · parent

... "will be used to offset costs for pensioners."

Our carbon tax worked at reducing emissions, and at being low economic impact. It was removed because we are a corrupt banana republic, not because it's unworkable.

comment 6y ago · link · parent

The existence of these bodies reduces the scope of the problem to merely one of first identifying an appropriate organisation that certifies the product type in question, and then ensuring the organisation is legitimate.

Do you think it's easier for a consumer to discover and vet certification organisations than it is for them to discover and vet transportation organisations?

The price signal you mention is the strongest one, which is why pigovian taxes are often the most effective approach to tackling negative externalities. It's a good example of the sort of government regulation that is many orders of magnitude more effective than individual action.

comment 6y ago · link · parent

Thanks for the reply and the feedback. Do you mean that my comment is worded in a way that describes the situation as hopeless, or that it's worded in a way that discourages discussing the ideas presented - or something else entirely?

comment 6y ago · link · parent

It's practically speaking impossible for consumers to discover and act on this information.

We buy our toothbrushes from a retail store, many transactions removed from the manufacture of the toothbrush, and every organisation in that chain would have to voluntarily agree to honestly report its transportation details. This is unlikely.

Even if it did happen, the onus would then be on consumers to interpret these details, perform a comparison between a number of available brands, and determine the most conscientious choice. And then review this decision periodically, because transportation contracts come and go. This is a substantial amount of work.

Even if consumers were able to do that amount of work, they'd then have to replicate that work for every single product, because everything goes through a similar transportation process. There is absolutely no way that any individual has enough time in their lives to research the transportation details of even a reasonable sampling of products used.

And that's not even considering the transportation issues in the supply chain!

As you observe, individual organisations also cannot act, because doing so makes them less competitive.

This is basically the same reason why individuals can't effectively tackle climate change. There is far too much information that's hidden, and far too much time required to effectively assess information, for individuals to influence anything.

Like with climate change, there is a solution, and it's regulation. The problem would vanish overnight if the EU, the US, and I guess now the UK all refused to allow docking of ships with flags of convenience, or even just ones flying flags from countries that don't ratify the maritime treaties.

And like with climate change, the solution is hampered not because of technical difficulties or cost, it's hampered by lack of will to spend a relatively small amount of money on something that only has a social good and not an economic good.

comment 6y ago · link · parent

My Magic Trackpad's haptic feedback has died, so now my trackpad has no feedback.

Sometimes I'm absentmindedly staring at the screen trying to click the desk, because it feels almost the same as the trackpad now.

Tactile feedback is very important!

comment 6y ago · link · parent

Lately I've simply been keeping the slow activity visible on screen, it's been enough that the flicker of motion when it finishes can pull me away from the distractions.

comment 6y ago · link · parent

Net neutrality doesn't apply to content providers differentiating service, because they're not common carriers.
1
151617
20