DreamBerd icon indicating copy to clipboard operation
DreamBerd copied to clipboard

Suggestion: Add function inlining

Open Spacerulerwill opened this issue 1 year ago • 5 comments

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.

Spacerulerwill avatar Jun 15 '23 09:06 Spacerulerwill

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! }

TodePond avatar Jun 15 '23 09:06 TodePond

Wanna submit a PR for it?

TodePond avatar Jun 15 '23 09:06 TodePond

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?

Spacerulerwill avatar Jun 15 '23 10:06 Spacerulerwill

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!

TodePond avatar Jun 15 '23 10:06 TodePond

We have #142 for that.

stohrendorf avatar Jun 15 '23 10:06 stohrendorf