Preferences

You’re getting some pushback but one look at pm_reduce_collapse and I’m glad I don’t have to work in this codebase.

I see the advantage of the inline lambdas, but also it seems like it would hamper the ability to test the functions which can often have intricacies that catch you out. I believe one of the principles of Tinygrad is that tests shouldn't be part of the core codebase and shouldn't add to the total linecount.

I think there is an opportunity there to have a tag in comments for tests.

Have a hotkey to generate an id so you could have

  # lift x+y out of reduce on lt               :testID: color_adjective_noun  
  ((UPat.var("x")+UPat.var("y")).or_casted() < UPat.var("c"), lambda x,y,c: (x < (c.cast(y.dtype)-y)) if no_range(y) and no_range(c) else None),
and it creates a test that exists away from the main codebase. A process that runs tests could scan the code for testID's, intelligently extract the relevant part of the code into the test harness and runs the tests. There would need to be some infrastructure needed to handle placing the code to be tested into the right context but you could have

  1. A codebase that contained no active code required simply to facilitate tests, 

  2. All test tags auto removable for distribution builds
You don't really want or need classical unit tests for compilers. You need a harness that you can feed a program representation into and get a transformed one out, then check the result -- ideally mostly just by running it, or alternatively by comparing the output against a reference.
How is that not a unit test?
I've hear people refer to it as an end-to-end test, where unit tests usually test a single class or function.
That's only if you subscribe to the London school of though, which results in a bunch of useless tests that are coupled to implementation details.
I agree. It is definitely readable but clearly formatting decisions were made to keep line count down over the flow of code. It isn't even just the variable names, things like having a function with a single return statement on one line, while legal, I cannot imagine why someone would do it in a non one off script code.
> having a function with a single return statement on one line, while legal, I cannot imagine why someone would do it in a non one off script code.

I agree. Seems to be a personal preference, but still feels odd.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal