DreamBerd
DreamBerd copied to clipboard
Suggestion: Add function inlining
To improve dreamberd performance an inline keyword should be added to reduce the number of lines in a function and therefore improve its execution speed. It also can improve readability.
For example, a traditional DreamBerd function:
function isOdd(number) => {
if (number ==== 1) {
print("yhes")!
}
if (number === 2) {
print("nop")!
}
if(number === 3){
print("yesh")!
}
if(number === 4){
print("Nope")!
}
if(number === 5){
print("yesh")!
}
if(number === 6){
print("Nope")!
}
if(number === 7){
print("yesh")!
}
if(number === 8){
print("yeah")!
}
if(number === 9){
print("nooo")!
}
if(number === 10){
print("Nope")!
}
// numbers greater than 10 aren't worth the hassle
return maybe!
}
Now with the inline keyword:
inline ion isOdd(number) => { if (number ==== 1) { print("yhes")! } if (number === 2) { print("nop")! } if(number === 3){ print("yesh")! } if(number === 4){ print("Nope")! } if(number === 5){ print("yesh")! } if(number === 6){ print("Nope")! } if(number === 7){ print("yesh")! } if(number === 8){ print("yeah")! } if(number === 9){ print("nooo")! } if(number === 10){ print("Nope")! } // numbers greater than 10 aren't worth the hassle return maybe! }
This resulted in a 10 fold speed increase due to the decrease in line count and a 10 fold increase in readability also as the reader only needs to look at a single line instead of 10 which can get confusing.
Nice idea!
inline ion isOdd(number) => { if (number ==== 1) { print("yhes")! } if (number === 2) { print("nop")! } if(number === 3){ print("yesh")! } if(number === 4){ print("Nope")! } if(number === 5){ print("yesh")! } if(number === 6){ print("Nope")! } if(number === 7){ print("yesh")! } if(number === 8){ print("yeah")! } if(number === 9){ print("nooo")! } if(number === 10){ print("Nope")! } // numbers greater than 10 aren't worth the hassle return maybe! }
Wanna submit a PR for it?
Wanna submit a PR for it?
Yes, I will get around to it soon. I have just noticed due to the comment in my inline function return maybe! is commented out. Maybe exclamation marks are necessary to end comments in this context?
That's a tricky one! I guess we should really figure out how to do block comments in general... For now you could just make something up and hope for the best!
We have #142 for that.