News for hackers. Stuff that matters.
Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @07:32AM (#27549323)
Two interesting takeaways:

> This is the beautiful thing about having a company that isn't on the stock market. Imagine you have a company that goes slower and slower every quarter, and then you confront the shareholders with the statement, that the way to solve it, is to do absolutely no new features for a quarter or two, refactor the code, learn new methodologies etc. I doubt that the shareholders would allow that. Luckily, we don't have any shareholders, and we understand the vital importance of this investment in the long run. Not only in the project, but also in our skill and knowledge, so we do better next time.

This is reassuring the notion of what I think actually matters, what the real essence is of developing a product, may that be a piece of art and entertainment (like here) or a productivity tool etc.

There are creators and there are consumers. We split them up by developers, designers, domain experts and so on, but what matters is that all the other participants, especially those who can exert power traditionally are not part of the essence and if not being careful and responsible, can easily add complexity and limitations that are entirely accidental and can even be harmful.

This reminds me of the agile manifesto, modern UX approaches and other processes that are driven by creators, but are often and very unfortunately being bent over backwards to fit into hierarchical power structures.

> TDD actually is the constant fast swithing between extending the tests and making them pass continously. So as you write tests, you write code to satisfy them basically at the same time. This allows you to instantly test what you write, and mainly use tests as specifiation of what the code should acctually do, which guides the thought process to make you think about where you are headed to, and to write code that is more structured and testable from the very beginning.

The important notion here is that TDD is not about tests and correctness, but about development. It continuously checks assumptions and explores the surrounding code, state and data until a sufficient solution is found.

If we squint a little we can see how closely related TDD with REPL Driven Development is. In essence it is the same thing and even has similar results, where the tests or REPL code can be left as an artifact for further, likely historical understanding.

We know now that neither is sufficient for a high degree of correctness, but they are certainly useful for understanding and development.

Re:TDD from the Factorio Team by rpastuszak on Friday June 18, 2021 @07:44AM (#27549380)
> The important notion here is that TDD is not about tests and correctness, but about development.

Yup, writing tests helps me sleep at night. TDD helps me manage my mental resources and iterate.

(another reason is communication--we code for our colleagues first, then for the machine: https://sonnet.io/posts/code-sober-debug-drunk/)

IIRC smalltalk had a workflow where you'd debug and write your program at the same time. You'd just reach a path that has not been implemented yet, break, implement it and continue.

Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @07:53AM (#27549419)
This „keeps working while it breaks“, does it have a name? It comes up in highly dynamic environments often like Smalltalk as you mentioned, but also Lisp, Erlang and others.
Re:TDD from the Factorio Team by dkarp on Friday June 18, 2021 @08:06AM (#27549487)
I think this may be "REPL driven development" popular in the lisp community
Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @09:55AM (#27550333)
I meant more at the system/vm level. You're going to use a REPL (of some sort) for this, but the system needs to accommodate failure and just keep going, while giving you the opportunity to fix and change things.

This has been implemented to varying degrees of reliability, granularity (in terms of preserving state) and utility. It's a common concept but I don't know the name for it!

Examples:

https://en.wikipedia.org/wiki/Continuation

https://en.wikipedia.org/wiki/Fault_tolerance

Maybe fault tolerance is the right word? But it doesn't imply that you actually modify and build the thing while it already runs.

Re:TDD from the Factorio Team by astrange on Friday June 18, 2021 @10:38AM (#27550827)
It's not a great idea because failure could mean anything, and so you can't necessarily fix it. It's better to start over from the beginning. This is what reliable systems like Erlang do.

https://en.wikipedia.org/wiki/Crash-only_software

Re:TDD from the Factorio Team by aiisjustanif on Saturday June 19, 2021 @01:07AM (#27557927)
In security of systems you would call the design “Fail open”. They are many systems that fail open.

An example of fail open design in the real world, is electronic magnetic locks at apartment complexes or business buildings. If the building loses power the doors demagnetize and unlock, then indefinitely remains open but failing because it is always open now. The opposite would be the building loses power and the doors fail close and lock the doors indefinitely when power is lost, and now people can’t escape.

Re:TDD from the Factorio Team by FigmentEngine on Friday June 18, 2021 @02:06PM (#27553111)
this could be many different concepts. fault tolerance is the most obvious, and self-healing and auto-rollback

a good read is ROC https://en.m.wikipedia.org/wiki/Recovery-oriented_computing

Re:TDD from the Factorio Team by mulmboy on Friday June 18, 2021 @10:37PM (#27557262)
> You'd just reach a path that has not been implemented yet, break, implement it and continue.

This is exactly what I do with the PyCharm - hit a breakpoint, write the code as it should be, and execute it in the debug REPL to do basic initial testing [repeat]. Extremely productive.

Re:TDD from the Factorio Team by wpietri on Friday June 18, 2021 @10:26AM (#27550658)
I appreciate this, but I still think it's a suboptimal approach:

> that the way to solve it, is to do absolutely no new features for a quarter or two, refactor the code, learn new methodologies

Even in a world without shareholders, we still are building things for users. 6 months without improvements has an effect on them, too. When possible, I think it's better to spread cleanup work out. Even if one spends 80% of the time on cleanup and 20% on features, that is much better for relationships than going dark for a quarter or two. And in my experience, continuing to do productive work during that period makes the behind-the-scenes improvements better.

Re:TDD from the Factorio Team by mikewarot on Friday June 18, 2021 @11:04AM (#27551114)
I've both watched all of Uncle Bob's videos (parts more than once), and been a long time Reddit/Factorio reader/game player. (The factory must grow!)

They did exactly what you suggested! The relationship with the users never went dark. They kept up with bug fixes, and kept feeding new features at a more than acceptable pace. [Edit: Here's the pace of their status updates, as evidence at https://www.reddit.com/r/factorio/?f=flair_name%3A%22FFF%22 ]

I didn't quite believe that Uncle Bob's lessons worked in the real world, but if the Wube team is sold on them, that's about as good as an endorsement as I'll ever get.

Re:TDD from the Factorio Team by wpietri on Friday June 18, 2021 @11:11AM (#27551184)
Yay! Glad to hear it.

I keep thinking I should try Factorio. But given amount of time friends have spent on it, I'm scared I'll never be heard from again. One of my friends has built a whole Grafana setup for it.

Re:TDD from the Factorio Team by bregma on Friday June 18, 2021 @12:31PM (#27552090)
Try heroin first. It's easier to quit.
Re:TDD from the Factorio Team by CreepGin on Friday June 18, 2021 @01:05PM (#27552490)
One would think this is a joke. But it's not. =D
Re:TDD from the Factorio Team by mikewarot on Friday June 18, 2021 @11:17AM (#27551251)
Factorio is easy to dump a ton of time into, if you are the type that likes solving puzzles and optimizing systems. You are wise in your caution.
Re:TDD from the Factorio Team by elevatortrim on Friday June 18, 2021 @01:50PM (#27552946)
True, and it is probably worth it. In my late 30s, I thought I'd never enjoy a game like I used to in my teen years. Well, Factorio was easily as much as if not more enjoyable. I do not know if I'll enjoy a game this much ever again.
Re:TDD from the Factorio Team by oarsinsync on Friday June 18, 2021 @03:41PM (#27554105)
If you spend your working hours solving problems and architecting systems, this game will be fun until you cross whatever your personal limits are for immediately grasping concepts.

As long as you're immediately understanding, you'll continue to have fun.

As soon as you need to stop and research to understand what it is that you need to do next, and then start to re-architect a bunch of things, you may or may not realise this is the same thing you do for a living.

Nothing quite like burning the candle at both ends, for fun and profit.

Personally, it's not for me. Others (including some of my colleagues) definitely do not share that sentiment.

That said, I enjoyed Mindustry for a similar period too. Factorio-lite tower-defence game.

Re:TDD from the Factorio Team by pault on Friday June 18, 2021 @04:19PM (#27554525)
You should take a look at satisfactory[0] if you haven't already. It's not (quite) as deep as factorio, but the game world is absolutely beautiful and immersive, and it's still in early access so new content is constantly arriving.I personally had to ban it because I played it for 300 hours in less than three weeks. I literally could not get myself to stop playing (until I did). :)

[0] https://store.steampowered.com/app/526870/Satisfactory/

Re:TDD from the Factorio Team by scotty79 on Friday June 18, 2021 @11:05AM (#27551120)
In this specific case, Factorio is such beloved product with such great development history that 6 months without updates is nothing.
Re:TDD from the Factorio Team by elevatortrim on Friday June 18, 2021 @01:45PM (#27552891)
It is not entirely without updates, the team have been pushing bug fixes for the most obscure edge cases that almost noone is running into.
Re:TDD from the Factorio Team by raxxorrax on Tuesday June 22, 2021 @04:22AM (#27589260)
There were times, when no new features were included and polish was the main goal. I don't think it was 6 months, but their FF seriously is a recommended read. Just about how problems manifested and the approaches to solve them. Not only interesting for game developers.
Re:TDD from the Factorio Team by wpietri on Saturday June 19, 2021 @10:05AM (#27560558)
Sure, but why eat into that belovedness if they don't have to?
Re:TDD from the Factorio Team by indigochill on Friday June 18, 2021 @04:15PM (#27554465)
Regarding the power structure observation, I've lately been weighing the merits of co-ops in the tech industry. Intuitively, it seems like a tech product owned by its users would lead to more product-centric decision-making. Leaving governance to shareholders who aren't necessarily directly involved in the product feels weird by comparison.
Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @06:30PM (#27555707)
I think so too. A lot of that free energy is in the FOSS movement it seems, and there are plenty freelancers and single consultants in tech. This is a strong indicator that there is enough developers who primarily want to create, while having agency, responsibility and a direct communication channel. So why not start businesses that share these values and bring consumers and producers closer together?
Re:TDD from the Factorio Team by wpietri on Friday June 18, 2021 @09:32AM (#27550085)
Yes, you're exactly right about REPL-driven development and TDD being the same spirit.

I took to TDD pretty easily because I was already used to doing short run-it-and-see-if-it-works cycles. The main difference was that instead of checking via eyeball, I talk the computer to check it. This is slightly slower early on, but so much faster once a program is big enough that manually checking everything would take a while.

Re:TDD from the Factorio Team by bjornjajayaja on Friday June 18, 2021 @09:25AM (#27550013)
I’d love to see a language where you write the tests and then the compiler creates the application code.
Re:TDD from the Factorio Team by kilburn on Friday June 18, 2021 @11:19AM (#27551277)
This is an active field of research. Search for "program synthesis".

We are advancing, but the current state is... not mind-blowing yet (albeit somewhat cool!). See [1] for an example interactive demo and [2] for the corresponding presentation.

[1] http://comcom.csail.mit.edu/comcom/#Synquid

[2] https://www.youtube.com/watch?v=HnOix9TFy1A

Re:TDD from the Factorio Team by hwayne on Friday June 18, 2021 @03:28PM (#27553956)
I was in the audience for that talk. The recording doesn't capture how much energy there was- we were all gasping and cheering throughout.

Still a decade off from production, though. That it doesn't just take "test cases": you have to know how to formally express the program properties, which is a separate skill from both unit testing and implementing.

Re:TDD from the Factorio Team by oats on Friday June 18, 2021 @09:44AM (#27550205)
Is this not almost how logic programming (prolog, etc.) works? You tell the language some things which are true, and then it'll be able to infer answers to "questions" you ask:

https://wiki.c2.com/?LogicProgramming

Re:TDD from the Factorio Team by victorNicollet on Friday June 18, 2021 @11:32AM (#27551416)
Let's say we work on the "reverse list" function. A few tests I could write are that the following clauses are true:

    rev([1], [1])
    rev([1, 2, 3], [3, 2, 1])
And maybe also that the following clauses are false:

    rev([1, 2], [1, 2])
    rev([], [1])
    rev([1, 1], [1])
Is Prolog able to infer, from the above, that rev([4, 5], [5, 4]) ? Or to synthesize the general form rev([H|T],R) :- rev(T, RT), concat(RT,[H],R) ?
Re:TDD from the Factorio Team by ffhhj on Friday June 18, 2021 @04:26PM (#27554611)
Sounds like NN training that could be achievable. The problem comes with unit testing, because the minimal testable unit could be more complex than a function.
Re:TDD from the Factorio Team by iamwil on Friday June 18, 2021 @11:31AM (#27551404)
Yeah. I've often seen TDD where you act both as the logic programmer writing the tests and the imperative programmer writing the implementation.
Re:TDD from the Factorio Team by JohnHaugeland on Friday June 18, 2021 @09:46AM (#27550233)
No. Not even a little bit.
Re:TDD from the Factorio Team by oats on Friday June 18, 2021 @10:24AM (#27550644)
Could... could you enlighten me please?
Re:TDD from the Factorio Team by bregma on Friday June 18, 2021 @12:35PM (#27552132)
It's incredibly easy. First, you start with a customer that actually knows exactly what they want.
Re:TDD from the Factorio Team by nyberg on Friday June 18, 2021 @12:09PM (#27551822)
This sounds a lot lke like minikanren (https://github.com/webyrd/Barliman) where you give test cases and Idris2 (https://github.com/idris-lang/Idris2) where you give type constraints as a tool for building programs.
Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @09:45AM (#27550220)
We typically write _sample_ tests in boolean logic, which isn't quite expressive enough for this.

But if you look at logic programming with more expressive systems you can have something like what you propose. We describe what we expect to have and the system deduces a result. Not quite what you want but its closer.

Now there is also an ubiquitous logic system that many use: static typing. In a sense you are describing the general properties of something and the compiler infers optimizations based on your assertions. The concrete program is not a line by line translation from your code to machine code, but perhaps looked at in its entirety.

I agree that there is a lot of merit in pushing these things further and further. Right now we're kind of in a stage of patching things together. But I hope and assume that programming becomes more holistic in the future. Ironically we have to look at the past first, there was a lot of momentum in this direction up until the 80's roughly.

Re:TDD from the Factorio Team by sidlls on Friday June 18, 2021 @10:59AM (#27551045)
How would this even work? At best you might get a set of class/function stubs with some minimal logic. At worst what you'd have is a compiler that is actually a complicated, truly AGI brain, which could produce some truly awful code. In which case you've simply reproduced TDD's normal result: truly awful code.

Aside from that, to produce a program that did what is actually required would require test cases and functions that cover the set of inputs and outputs. This is trivial for mathematical functions, but impractical (or impossible) for more general applications (e.g. anything dealing with human inputs).

Re:TDD from the Factorio Team by mikewarot on Friday June 18, 2021 @11:08AM (#27551149)
You could just use a fuzzer to generate code, and run tests on the output. Each new test would approximately double the run time until a new "correct" output was found.

This doesn't become practical until you can do it on a quantum computer with millions of cubits.

Re:TDD from the Factorio Team by iamwil on Friday June 18, 2021 @11:28AM (#27551369)
This is kinda what logic programming is, like in prolog. You tell the computer what you want, and it finds the answer for you.

TDD is where you both write what you want, and you do the implementation also.

Re:TDD from the Factorio Team by phtrivier on Friday June 18, 2021 @04:07PM (#27554394)
I would like to see this language handle some lawmaker-specified code.

Show examples of French retirement pension computation, and watch if a computer can actually commit petit-suicide.

Re:TDD from the Factorio Team by astrange on Friday June 18, 2021 @10:32AM (#27550741)
Well, that's how machine learning works.
Re:TDD from the Factorio Team by mikewarot on Friday June 18, 2021 @11:22AM (#27551305)
Machine learning requires a problem that you can have partially correct, so that it can climb the gradient to optimize on. If you can build tests that have an analog instead of pass/fail output, you could, in theory, do it with machine learning.

Beware that machine learning in a single pass/fail is more like having an infinite number of monkeys trying to write the works of Isaac Asimov.

[Edit/Update] All of the tests could be individual values, so non-zero (but nowhere near all ones) might help. Thanks for making me reconsider this, sdenton4.

Re:TDD from the Factorio Team by sdenton4 on Friday June 18, 2021 @12:02PM (#27551762)
Not all ml is gradient based. Other options exist: Bayesian black box optimization (like vizier), or genetic algos. And Vizier is actually quite efficient for small problems.
Re:TDD from the Factorio Team by peheje on Friday June 18, 2021 @05:19PM (#27555162)
With genetic algorithms you still need to be able to calculate a fitness. Usually a test is fail/success. There's no fitness in that. I would guess the other optimizers also need such a signal?
Re:TDD from the Factorio Team by sdenton4 on Friday June 18, 2021 @06:10PM (#27555545)
Success/failure is just a binary classification signal: you can look at how it correlates with your target variables, how noisy it is for particular choices of variables over multiple trials, etc. The noisier it is, the harder it is to learn, but such is life.
Re:TDD from the Factorio Team by peheje on Friday June 18, 2021 @06:29PM (#27555693)
I think it would be impractical for a naive fitness function that is 0 for failure and 1 for success. Wouldn't the signal be too difficult to find? GA would be brute force until you find code that passed a test. I don't think tests for factorio are trivial.

Maybe you could move the goal/fitness function along the way. So start with something that compiles. Then having the desired input output. Etc.

Re:TDD from the Factorio Team by peheje on Friday June 18, 2021 @06:45PM (#27555842)
Addendum. More tests. I see. Would you then lead the algorithm along a trajectory. If you can pass this simple test you would probably be able to pass this as well then this... Babysitting it along the way. Ideally you wouldn't need to, but maybe to make it possible..
Re:TDD from the Factorio Team by sdenton4 on Monday June 21, 2021 @03:12PM (#27582935)
Check out Thompson Sampling and multi-armed bandit problems for how this can work out in real life. (I tend to think this approach is much better than genetic algorithms...)

Each 'bandit' is a random boolean outcome, governed by some hidden success probability. Thompson Sampling trades of exploration and exploitation. If there's no successes ever, then all bandits are equally bad, and you just keep exploring randomly until you find some success (or give up). If you do have some success, you can try to exploit it.

For a problem with continuous parameters, you can discretize the parameter space by binning, and then choose randomly within a bin for each trial. 'Exploiting' a particular bin might lead to breaking it into more bins for finer resolution.

Re:TDD from the Factorio Team by astrange on Friday June 18, 2021 @12:52PM (#27552338)
I was actually thinking about decision trees.
Re:TDD from the Factorio Team by CraigJPerry on Friday June 18, 2021 @09:19AM (#27549967)
For those curious about REPL driven development, this is a good example that i ran across recently:

https://gist.github.com/daveray/1441520

Even if you don’t follow along and try it, you can probably get the gist of how experimental / exploratory you can be.

Re:TDD from the Factorio Team by adamkl on Friday June 18, 2021 @09:22AM (#27549993)
For those who want to see some REPL driven development in action:

https://vimeo.com/230220635

Re:TDD from the Factorio Team by truetraveller on Friday June 18, 2021 @11:06AM (#27551131)
TDD is basically automated and "named" REPL-driven development. Which is very nice!
Re:TDD from the Factorio Team by infogulch on Friday June 18, 2021 @04:15PM (#27554471)
Oh that's an interesting take, and feels right to me. So the thing that holds back TDD is ergonomics (compile time/cached results) and maybe marketing.
Re:TDD from the Factorio Team by lugged on Friday June 18, 2021 @09:25AM (#27550020)
Its almost like Test Driven Development is the practice of using tests to drive development.
Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @09:57AM (#27550362)
Much of TDD mantra is less about development but about (perceived) correctness, the article in question emphasizes the development part, where they describe their AHA moment.
Re:TDD from the Factorio Team by berkes on Friday June 18, 2021 @10:44AM (#27550898)
> Much of TDD mantra is less about development but about (perceived) correctness,

I have (seriously!) never heard it reference like this at all. Every introductory article, every book, every tutorial, every video about TDD (or BDD) that I consumed, emphasised that it is about "workflow", about "a way of development" and not about percieved correctness.

Do note that the crucial different is that TDD > automated testing. In the sense that with TDD you write automated tests (that live in a test suite). But that "writing tests" or "developing a testsuite" is not nessecarily TDD.

Re:TDD from the Factorio Team by dgb23 on Friday June 18, 2021 @11:55AM (#27551673)
Yes in relation to automated testing it is obviously focusing on the development aspect, but as a whole method there is an at least implied and sometimes explicitly emphasized correctness benefit, that doesn't just come from automated tests but from the method of driving design through testing.

In my personal opinion this claim goes too far. I think we can often explore aspects of design through code (including tests) but it can't be the main driver of design in any circumstance, nor does it by default or in general make our modules and programs more correct.

The key benefit of doing this is that we have to think of code in terms of invariants and testability. But that is just one of many, sometimes conflicting factors and there are certainly more approaches to doing this than writing automated (unit-) tests.

Re:TDD from the Factorio Team by hwayne on Friday June 18, 2021 @03:29PM (#27553968)
The original TDD book said it was both.
Re:TDD from the Factorio Team by ffhhj on Friday June 18, 2021 @04:49PM (#27554882)
> (perceived) correctness

Right, in TDD there is "always" a range of values against which you are not testing. A developer can only create a finite amount of tests, and the program will fail with any of the missing permutations.

Re:TDD from the Factorio Team by lugged on Friday June 18, 2021 @11:48AM (#27551597)
Also need to echo the above.

The TDD book itself is barely even about testing, it's almost entirely about development processes and different types of refactoring and how to use tests to get from a to b.

Correctness is rarely emphasized if at all.