5 ms·
The codebase is quite something. I thought the author had lost his mind, declaring dozens of new functions to simply wrap inbuilt functions and religiously not
by pizzathehut1 5y ago
The codebase is quite something.
I thought the author had lost his mind, declaring dozens of new functions to simply wrap inbuilt functions and religiously not using classes.
Then I realized it probably cuts the bundle size by 2/3rds to remove every "this.longBuiltinFnName()" and replace it with a minified function call.
- dotancohen 5y agoLaravel has a similar convention, wrapping everything in static classes. I hated it at first - and still hate the convention outside Laravel - but in context it works well. Not for minification, but rather for reducing cognitive load while maintaining code while preserving good separation of concerns.
- hubeh 5y agoThis is done mainly due to the PHP autoloading limitations - classes are able to be autoloaded but functions aren't.
- onion2k 5y agoIt'd be interesting to see if the brotli/gzip size is smaller using this sort of strategy. I suspect the benefit is lost after compression
- Kiro 5y agoWhere can I see it in the code?
- vorticalbox 5y agohttps://github.com/tinyplex/tinybase https://github.com/tinyplex/tinybase
- Kiro 5y agoYes, but what files specifically use the pattern described? I had a quick look through some files and didn't see anything like that.
- graderjs 5y agoCheck the cross cutting concerns, could be a good place to look to find code that tries to save on its re-use. I looked in ./src/common/ and found https://github.com/tinyplex/tinybase/blob/main/src/common/array.ts https://github.com/tinyplex/tinybase/blob/main/src/common/ar... which could be to some extent and example of what the OP is talking about.
- wccrawford 5y agoI think they were probably referring to https://github.com/tinyplex/tinybase/blob/main/src/common/array.ts https://github.com/tinyplex/tinybase/blob/main/src/common/ar... and the like for wrapper array.map and array.forEach and array.sort. I don't think there's dozens, but there's a fair few. Most of the stuff in the common directory seems to be standard patterns they use, so it's doing more than just wrapping a function.
- apatheticonion 5y agoClasses can be effectively minified also class Foo { foo() {} #bar() {} } Becomes: class f { foo() {} b() {} } Combined with any type of compression the negligible difference is eliminated. Though it is true that static functions might be more optimisable in some cases, I'd say that on balance, the effect on maintainability is too significant for the returns. I'll take DI and testability over maybe a few kb difference
- jamesgpearce 5y ago> I thought the author had lost his mind Quite possible. This was a journey! https://tripleodeon.com/2022/01/software-without-compromise/ https://tripleodeon.com/2022/01/software-without-compromise/ When I first started thinking about this project, classes still meant a bunch of transpilation overhead (which dates the origin story!). I persuaded myself that plain old objects with TypeScript interfaces would strike a better balance between performance, size, and developer experience. So I ended up with a pattern like: const longMethod1 = () => {...}; const longMethod2 = () => {...}; return {longMethod1, longMethod2}; These 'methods' can still call each other by name, and it minifies like a champ.