Files
Threadwell/archive/threads/rfleury/2026-06-02-the-first-way-people-usually-learn-code/2026-06-02-ndwork-a-function-explicitly-limits-the-variables-that.md
T
2026-08-25 16:26:52 -04:00

1.8 KiB
Raw Blame History

title, type, source, source_url, author, handle, post_id, date, archived, draft, tags, description, in_reply_to, parent_post_id
title type source source_url author handle post_id date archived draft tags description in_reply_to parent_post_id
@rfleury A function explicitly limits the variables that its code depends on. archive twitter https://x.com/ndwork/status/2061896821023383829 Nicholas Dwork ndwork 2061896821023383829 2026-06-02 2026-08-25 false
archive
twitter
rfleury
@rfleury A function explicitly limits the variables that its code depends on. 2061619837877780961

Source

Branch

1/ @ndwork ^2061896821023383829

@rfleury

A function explicitly limits the variables that its code depends on.

For many functions, they can be independently tested. When possible, that also seems useful. If there’s a bug, it’s highly likely not to be inside the function.

These things make functions extremely useful.

2/ @rfleury ^2061955393216200840

No. By adding entry points which are independently tested (e.g. in a vacuum, removed from context), you are combinatorially increasing the number of possible test cases. It’s vastly easier to exercise one single codepath than several thousands.

Second of all, sub-scopes also allow limiting exposed variables to other scopes. If a scope fairly far into a function depends on the entire set of exposed variables that came before, functions do not stop that, because you’d simply need to pass them all. There is way less boilerplate and way less complexity in the single codepath version.

3/ @ndwork ^2062015909842350192

@rfleury

I’m taking the fact that you didn’t tell me to delete my account as a huge mark of success. :)

All the best Ryan.