Hacker Newsnew | past | comments | ask | show | jobs | submit | quii's commentslogin

Well, the point I'm making is the technology choices we make, have an impact on the experience of the user, literally the 2nd paragraph.


OP here! The hx-boost hijacks links to make it feel like an SPA. I added it for fun NGL, removed it now though :)


Aha well that's interesting, I didn't know about that feature.


OP here! The hx-boost hijacks links to make it feel like an SPA. I added it for fun NGL, removed it now though :)


Converting data to a HTML string is not a performance bottleneck you'll be worrying about. I wasn't worrying about it much in 2000, and you really shouldn't need to in 2023.


I think both are valid, as i mentioned in the article, for this particular case, the psuedo content-negotiation felt right


Thanks for taking the time to read the article :) A lot of the comments here seem to implying that I claim "htmx is the one hammer to solve all website needs", even when I explicitly say SPAs have their place in the article.

A hypermedia approach is the nice happy medium between a very static website and an SPA, not sure why so many people are close-minded about this possibility.


Hi, author here.

The project is open-source (https://github.com/quii/learn-go-with-tests) so there's a few options available to you.

In releases, you'll find PDFs and epubs, I'm pretty sure most epub readers will let you use a dark mode. Or you can just read the markdown files on GitHub, which also supports it.


Thanks, I was looking for this but couldn't see it for some reason.


Thanks for this, it's an important comment because it's linking to the master branch but I changed it to main a while ago so master is quite far behind.


Net negative value in that move then?


I'm not sure how they're mutually exclusive. Also TDD is more of a _design_ technique than a testing technique. I've worked in languages with extremely expressive typesystems (like Scala) and I still practiced TDD


> I'm not sure how they're mutually exclusive.

Where did I say that? I just meant, and my apologies for not being clear, focus should be types, ofc you still need tests. But not as many as a decade ago and more important, people must drop this dogma that tests are the key to everything. There are not and the more tests a codebase has the worse its quality and maintainability.

> I still practiced TDD

You can do this ofc but my experience differs: Once you have an excellent type system, both in terms of language features and tool chain eg editor, you can literally code for days without running even the compiler once. This is pure flow and very much the opposite of TDD. But the entry barrier of is much higher than TDD. Don't get me wrong, you still need tests but TDD?? IDK, this feels like trial-and-error-coding from 2010. I mean if we still used all Ruby, yes tests and TDD everywhere but the environment has changed.


> There are not and the more tests a codebase has the worse its quality and maintainability.

I'm fully sold that types are important, personally I would object to starting any mid- to large-scale project in a dynamically typed language, but this doesn't ring true at all.

When you're writing and refactoring code that uses complex logic, you aren't necessarily able to encode that logic in the type system. Carefully written tests allow you to confidently edit the code without worrying that you might have broken something in the process.

If anything, strong type systems allow you to change the way you write and structure tests (more towards property-based testing as opposed to dumb test cases), but I wouldn't advocate completely doing away with them.


> but I wouldn't advocate completely doing away with them.

didn't say this

> Carefully written tests allow you to confidently edit the code without worrying that you might have broken something in the process.

yes true but again you get this with typed code without any tests for 80% of the code as well, look, it's about the quantity and what you are going to test. with types you need way less unit tests (some like ben awad say none!) but still integration tests. still doing tests like crazy and like it's 2010 defocusses your devs and makes refactoring much more tedious, change a small thing and rewrite twenty unnecessary tests from a too ambitious test warrior who didn't understand types. this creates a notion where codebases get stale and untouched for years. nobody likes to refactor test code bc it's an unattached piece of code which complicates things more than it helps, it rarely feels like a true spec but rather like some random code and the next one wonders why his predecessor wrote this test at all. this is so the past idk why people are worshipping this.

Write tests where types don't help anymore (integration tests!) and things are crucial, otherwise focus on the core logic. I have rather devs who write excellent typed code with just very few integration tests than somebody who drives nuts and goes down the full rabbit hole writing 10x more test code nobody asked for than actual code paired with such blog posts like from OP on top, they've missed the boat.


> doing tests like crazy and like it's 2010 defocusses your devs and makes refactoring much more tedious

I'm fully sold on this as well, but:

> it's about the quantity and what you are going to test

I'd say it's more about how you're going to test. What is covered by the type system should be handled by the type system, that's an absolute no brainer, using tests, or even worse, comments or conventions as opposed to types is just objectively wrong.

Because you can now be confident that trivial mistakes will be caught by the compiler, you can have actually meaningful tests, like "this property is satisfied", as opposed to "this object has this field set to this string".

So I wouldn't say "write less tests", I'd say "since types free you from the burden of testing stupid things, write better tests".


> with types you need way less unit tests

It's a misconception that developers who use dynamically typed programming languages write tests that perform tasks of a static type system. They do not write tests like this:

    assertException(() => upcase(12));
    assertException(() => upcase(true));
    assertException(() => upcase(null));
    assertException(() => upcase(new Object()));
    ...
They write tests like

    assertEquals("TEST", upcase("test"));
    assertEquals("HELLO, WORLD", upcase("hElLo, wOrLd"));
    assertEquals("BLA123", upcase("bla123"));


Having used both dynamic and statically typed languages rather extensively, I always end up recreating some subset of the type system in the test suite for dynamically typed languages. Often to at least test that the functions correctly handle erroneous input. Taking your example, I would definitely have at least one of those assertException kind of tests, and more of them (but automatically generated) if using a property-based test system where I could say something like: any type but string should result in an exception/error result. Now, this wouldn't be exhaustive (again, sans automation), but I'd have at least one test covering this.

Those tests that you list later are "happy path" tests. We want to know that that works, but we can't rely on only that sort of test especially if the type system doesn't work with us to avoid incorrect inputs to the function.


I currently use a dynamically typed pl in my professional capacity (statically typed pl in my side projects). I write a lot of tests, and 0 of them assert the type of the flowing data.


So you have no tests that would trigger an error/exception by giving bad data? I'm not saying that I'd, necessarily, call out the type explicitly, but I would give bad data to trigger the exceptional control flow/guard which can be tantamount to specifying a type. Of course, this also depends on where the function sits. If it's an internal/private function in a module that only my own functions would call I can more safely focus on the happy path. But if it's part of the interface to a module, then I want to make sure that users of the module get proper feedback/responses, whatever the contract is (be it a result type or an exception or a default value). I mean, that's a large part of the value of testing: ensuring that the code matches the specification/contract that you present to users.


Elixir/ecto has something called schema changesets that are a very robust way of validating user input. I do test against bad values (not just types, out of range, correct type but unsupported value, etc), but only really at data ingress, and no where else.

Honestly if a sad path causes a typing error in elixir it's not the worst thing. Sentry will catch it, only the user thread crashes, and you go patch it later.


> I do test against bad values

A type is literally a description of a set of valid values. So when you say you test with bad values, then the answer is: you could use types and would not need these tests anymore.

However, the more interesting question is: is your typesystem capable of expressing your type and, if so, is it worth the effort and implications to do so.

But on a more theoretical level, OP is right: you _can_ save the tests with, given a powerful enough typesystem.


> you could use types and would not need these tests anymore.

No. These are not internal contracts, these are contracts with user input. In a statically typed language, You are still advised to write tests that your marshalling technique provides the expected error (and downstream effects) that you plan for, if say the user inputs the string "1.", For a string that should be marshalled as an integer.

> A type is literally a description of a set of valid values.

That is generally not the case. There are, for example cases where certain floating points are invalid inputs (either outside of the domain of the function or a singular points), and I don't know of a mainstream PL that lets you define subsets of the reals in their type system.

In go, or c, c++, or rust, you could have a situation where a subset of integers are valid values (perhaps you need "positive, nonzero integers", because you are going to do an integer divide at some point) and that is not an expressible set of value in that type system. Ironically, that is a scenario that IS typable in Elixir and erlang, which are dynamically typed languages.


I think you are referring to concrete/mainstream languages - so what you are writing is correct from a practical perspective, i.e. I would do that. From a theoretical perspective however it is not necessary, even if such a type-system might not exist yet.


You can retreat to your corner of theory if you wish, I'll actually build stuff. The real world has scary things like malicious actors that will send payloads designed to break your system through side channels like timing and cosmic rays that can flip bits on your disk and erase the guarantees that you believed you had in your type system.


You are being needlessly antagonistic. On HN of all places we should know that research in type theory isn't purely academic navel gazing.


Isn't it great that we have both theory and practice and both impact each other? Makes our profession so much more fun! :)


> But on a more theoretical level, OP is right: you _can_ save the tests with, given a powerful enough typesystem.

Yes and no. The trick is building a type system simultaneously strong enough to encode the properties you want, and weak enough that it's statically decidable.

There will always be properties you can't encode in a (useful) type system.

It's a fine line to walk, really. There's an argument to be made that most of the times we don't actually need Turing-completeness, and we'd better off using only types to encode computations, but OTOH I don't really want to think about what coinductive types I must define to solve a problem that could be solved with five lines of javascript instead.


> There will always be properties you can't encode in a (useful) type system.

If you define useful by "we know that the compiler will finish in finite time" then I agree. And that's indeed a good point! In practice, there will always be runtime tests, at least for how long any of us and our children will live. :)


A type system can do way more than the simple things from your first code block. This is misleading in terms of what a powerful type systems can do.

Re your second code block: This can be typed with literal types, no need for tests at compile time.


Let's say you have implemented a function that sorts a list in Haskell, which has a relatively strong type system. How do you make sure that it sorts the list and does not reverse it instead, how do you know that your job is done?


This is not the same problem AFAIU. You don't know whether your tests encode the correct specification either, but you must run them first to find out whether they pass, but with (dependent) types you can have the sorted list property encoded in compile time, but still can't be sure whether it is correct.


I recently implemented Conway's Game of Life in Agda. I still had to write "test cases" to get the whole thing right: https://github.com/fzipp/agda-life/blob/18dda7f45541d2e8f47c...

Sure, they are validated at compile time because they are propositions as types, but in the end they are still basically test cases: expected output for a given input, and the compiler is the test runner.

I don't know how to encode the full "Game of Life" property as dependent types, I am still an Agda newbie.


In this context, I think we should not call them "tests" to not mix them up with "runtime tests". Even though they are indeed tests in a sense


Sure, I don't know what the correct term is. But I personally did not really gain anything from the type system that helped me get the logic of the program right. Whether a Turing complete type system "runs" my assertions at compile time, or a test runner does it on save does not make a difference to me. Actually, I could measure the compile time for this simple one-page program in seconds, while the Go tools compile and test a Game of Life implementation in a fraction of a second.


> both in terms of language features and tool chain

What would you give as examples for language features and toolchains that enable the workflow you are suggesting?


TS has by far the most advanced compile-time type system followed by Rust.

TS has the best and most responsive editor support (tsserver). I know that Rust's is much slower but IDK much more than that.

Re ecosystem and build system: TS' build system is not trivial but it's very flexible and has a bigger ecosystem.


Idris and F* have a much much more advanced type system, compared to Typescript and Rust. But even if you deem these languages not "mainstream" enough, there is still e.g. Scala which has a typesystem that beats the one of Rust by far and also the one of Typescript, minus certain special cases where Typescript is really nice.

It is great to see though that even frontend-mainstream languages like Typescript start to get proper support for type-systems (especially considering that they had to do it on top of Javascript).

Very excited to see where we go with languages and I agree with you that TDD should now by default mean "type driven development". :)


Just because something isn't skilled doesn't mean it's not important or doesn't bring value. The people who do these jobs deserve a decent wage and respect, not psuedo-wage-slavery


That’s a political problem to solve with higher minimum wages/max work hours or universal basic income and universal healthcare.


Well not quite. It’s an economic problem in that if you don’t pay your workers decent livable wages then they won’t be able to continue to do a decent living while working for you.

The whole idea of “this is a low paying job, anyone can do it, I’m paying you very low because you should get a better job” now that sounds like a political problem! It is all the invented justification to keep wages low. It’s also a pretty stupid argument but has weight because an entire political party makes it.

The thinking around these jobs needs to change; you can’t pay people like shit and then expect them to be moral and upstanding workers.


It’s a more immediate economic problem if paying employees more than competitors causes your products to become uncompetitive and you lose business because people shop elsewhere where prices are lower.

The wages aren’t low because of an ideology, the wages are low because if person A doesn’t agree to the low wages then the employer can hire person B.

Similarly, wages aren’t high in tech/finance/law/medicine because people think they “deserve” it, they are high because those employees have options to work elsewhere.

One employer deciding to be altruistic and paying more isn’t going to fix the problem.

Therefore the solution is to either give people better options for earning income (long term solution involving educating them and more), and increasing minimum wage and especially overtime wages.


> The wages aren’t low because of an ideology, the wages are low because if person A doesn’t agree to the low wages then the employer can hire person B.

This would be true iff the labor supply was perfectly elastic wrt to wages but we have repeatedly seen that this is not the case.

Paying your employees higher isn’t altruism as much as an investment in the health of your business. It’s either that or you deal with higher turnover, insurance security etc.

Wall Street has consistently pressured the larger employers to cut labor costs as much as they can; there is a lot more variation in wages offered by smaller businesses. Wall Street is always focused on quarterly growth and that is the “ideology” that’s ripping apart the middle class across the US as employers fail to invest in the long term viability of the communities they operate in.


We have decades of evidence where companies that opted for lower labor costs were more successful than their competitors. There's a reason all manufacturing moved to China, and there's no more mid market retailers left in the US.

And labor supply elasticity shouldn't matter over a span of decades, any mis-pricing would have shown itself, at least in the context of maximizing profits. If anything, the comparatively overpaid US workforce is/was the "mis-priced" part of the equation.

Also, larger businesses can afford to pay more, especially by way of tax advantaged benefits:

https://www.ivyexec.com/career-advice/2015/do-big-companies-...

My argument is that ideology has nothing to do with how much people are paid, it's supply and demand curves (over the long term). If people had better options for employment, they would be paid more. If employers had fewer options for employees, they would have to pay more. The rest of the up and coming world would have taken a bite out of US workers' pay no matter what.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: