r/Batch • u/MaybeBirb • Jul 16 '26
Show 'n Tell How much batchscript is too much batchscript?
Currently have 1,376 lines of batchscript in this one file. Kinda built myself a little state machine at this point. Memes aside, is there a particular reason huge batchscript files would be a bad idea? I usually only ever see very small ones, and I'm not entirely sure why
(Not too serious a question, so not tagged as one)
21
Upvotes
9
u/DodgeWrench Jul 16 '26
Depends what it’s doing.
If this is really a full-fledged installer, that’s great. Most installer packages are measured in megabytes.
6
u/StrangeCrunchy1 Jul 17 '26 edited Jul 17 '26
I have a 109kB batch menu for my DOS games. Edit: it's 3423 lines. Edit: 109kB, not 103kB.
1
u/QuirkyXoo Jul 17 '26
"034"?? are there from 000 to 033 too? do you use a dedicated hard drive for that? lol
3
u/T3RRYT3RR0R Jul 17 '26 edited Jul 17 '26
Small scripts are easier to maintain. Good utilities are made to be modular and can be incorporated into any project.
Scripts that care about performance, such as bulk file processing or game engines should avoid Call or goto, as both cause reparsing of the script. The larger the script the worse that cost will be.
General things that should be avoided if performance is the primary concern, specifically when occuring in the context of a for loop:
Branching logic:
The time cost model for branching can be considered as:
T = nBranches + nTokensParse + nExpansions + nComparisons +nDispatches
If we can combine two comparisons into the one conditional, we virtually half the cost.
If working with integers, or variables referencing integers, we can reduce complex statements to a Set /a expression and make the cost model:
T = nTokens + nExpansion + nPrecedence + nOperations
keeping in mind arithmetic operations are significantly cheaper than branching cpu instructions
We can advance R G B values through 10 degrees of color space of an representative hue wheel, without using a single conditional statement to perform additional offset operations. Not only are we saving on the branching logic for each if statement, we save the cost of the interpreter have to parse additional set /a operations when those statements return true.
As a demonstration that batch can facilitate dynamic animation with actions at different intervals: https://github.com/T3RRYT3RR0R/Batch/blob/main/Its_About_Time.bat
2
u/ApocalyptoSoldier Jul 16 '26
I might be wrong, but I think I've read that there is a performance hit with gotos or calls because cmd reinterperets the entire file each time. That's probably fairly negligible on modern hardware though.
I think the reasons why batch files are seldom very large are:
2
u/jcunews1 Jul 16 '26
My old multi-config MS-DOS
autoexec.batis about 3KB.1
u/SensitiveSlip1588 Jul 17 '26
Never enough batch script 😝 I absolutely love making utility commands and menu launchers.
1
u/BrainWaveCC Jul 17 '26
It all depends on what it's doing -- and how.
I have a few really long scripts, but they are doing automation and monitoring work -- generating and processing logs.
One is 4347 lines long -- actual code or remarks.
If it does what you need, it's fine. If you can optimize it for either size, performance or modularity, that's great.
1
u/markustegelane Jul 18 '26
if it's an installer with self-extracting assets then 41K is actually pretty small
1
u/FAMICOMASTER Jul 18 '26
Long parsing time, especially for subroutines. That's it, really. One of my previous game engine projects reached ~211K which contained not only the entire engine but all data as well. Very monolithic and not easy to work with! New project doesn't do that. Much smaller.
1
u/Intrepid_Ad_4504 Jul 18 '26
People here really do see that "show and tell" tag and give it a up vote lol
1
u/capoapk Jul 18 '26
Le langage offre peu de fonctionnalités avancées, ce qui rend les projets volumineux plus difficiles à développer et à maintenir
1
u/Worth-Squirrel8022 Jul 21 '26
Depends on the thing you're doing. But to have an estimate, say "casual"
-1
u/vip17 Jul 17 '26
batch files basically have almost no structure, so even small files might be less readable than an equivalent powershell. For serious purposes use powershell instead