In several different topics people have applauded the barrels + tubes sorting method, presenting it as a solution to a problem, and then boggled at my dislike for that method. I have struggled to find a way to explain why I dislike it and recently some serendipity while watching DW20 current videos gave me a way.
In his first base he has a sorting system which uses traditional(ish) chests whereas in his new base he uses the barrels. Notice in his first base he is able to sort (almost) everything into ~15 chests with a smattering of barrels. His new base, however, requires 81 barrels and doesn't catch as much as his previous 15 chests.
Where is the serendipity? The frame quarry the built in between. To control the quarry he wrote a script which allows him to run a command. To catch the command he chains a series of if statements, like this (example in Python since I know that syntax and is quasi-legible to non-programmers):
Readable? Yes. Understandable? Sure. Extensible? Nope. Which is why in the comments I lamented that he should be using an array look-up. Someone else pointed out that DW20 never claimed to be a master programmer and I retorted that in today's day and age, esp. in scripting languages like Lua (the language ComputerCraft uses) array lookups are a dead simple concept. I then pointed out he seemed to have a grasp of the idea even if only in terms of Minecraft objects.
What's an array lookup and why is it better? Well, it looks like this.
Why is this form considered better. Well, for starters, it is a heck of a lot shorter. We're not constantly testing the command variable, we're checking it once against the array, commands, so it runs faster If it is in there, we use it to call that command. But secondly, it is easily expandable. To add "moveUp" and "moveDown" to the if chain we require 4 more lines and make the logic of the code quite a bit longer. To do the same for the array is 2 lines which are clear, we assign the commands to the functions in the array. The logic later on is untouched.
Ok, but what does this have to do with barrels? Barrels accept one, and only one, thing. Running a tube past a series of barrels is like checking the command variable against the chained if statement. "If it fits here, insert, else if it fits here, insert, else if it fits here, insert..." Is it simple to set up? Sure, but as the system grows the run times slow down (look how long it takes his Xycraft stuff to filter), it gets harder to extend (requiring far more space) and harder to modify as it grows. Barrels and tubes are the Minecraft physical representation of the chained if statement.
In his first base he has a sorting system which uses traditional(ish) chests whereas in his new base he uses the barrels. Notice in his first base he is able to sort (almost) everything into ~15 chests with a smattering of barrels. His new base, however, requires 81 barrels and doesn't catch as much as his previous 15 chests.
Where is the serendipity? The frame quarry the built in between. To control the quarry he wrote a script which allows him to run a command. To catch the command he chains a series of if statements, like this (example in Python since I know that syntax and is quasi-legible to non-programmers):
Code:
if command == "moveFoward":
forward()
elif command == "moveBack":
back()
elif command == "moveLeft":
left()
elif command == "moveRight":
right()
elif command == "Dig"l
dig()
else:
print("No such command!")
Readable? Yes. Understandable? Sure. Extensible? Nope. Which is why in the comments I lamented that he should be using an array look-up. Someone else pointed out that DW20 never claimed to be a master programmer and I retorted that in today's day and age, esp. in scripting languages like Lua (the language ComputerCraft uses) array lookups are a dead simple concept. I then pointed out he seemed to have a grasp of the idea even if only in terms of Minecraft objects.
What's an array lookup and why is it better? Well, it looks like this.
Code:
commands = { "moveForward" : forward,
"moveBack" : back,
"moveLeft" : left,
"moveRight" : right,
"Dig" : dig
}
if command in commands:
commands[command]()
else:
print("No such command!")
Why is this form considered better. Well, for starters, it is a heck of a lot shorter. We're not constantly testing the command variable, we're checking it once against the array, commands, so it runs faster If it is in there, we use it to call that command. But secondly, it is easily expandable. To add "moveUp" and "moveDown" to the if chain we require 4 more lines and make the logic of the code quite a bit longer. To do the same for the array is 2 lines which are clear, we assign the commands to the functions in the array. The logic later on is untouched.
Ok, but what does this have to do with barrels? Barrels accept one, and only one, thing. Running a tube past a series of barrels is like checking the command variable against the chained if statement. "If it fits here, insert, else if it fits here, insert, else if it fits here, insert..." Is it simple to set up? Sure, but as the system grows the run times slow down (look how long it takes his Xycraft stuff to filter), it gets harder to extend (requiring far more space) and harder to modify as it grows. Barrels and tubes are the Minecraft physical representation of the chained if statement.