Project

General

Profile

Feature #17786

Updated by nobu (Nobuyoshi Nakada) 8 months ago

I'm submitting this in the same spirit that ''endless methods'' ``endless methods`` was, to promote and produce more concise and easier to write|read code. 

 #### Proposal **Proposal** 
 This is a proposal to introduce a new keyword ``ends`` (or ``endall``) as a terminal point to resolve the end of nested ''loops|conditionals''. ``loops|conditionals``. 

 #### Why **Why** 
 It's a common code occurrence to have multiple levels of loops and/or conditionals, which require separate ``end`` keywords to designate their 
 termination points. The ``end`` statements themselves are merely for syntactic purposes. 

 It would be a benefit to programmers, and code readers, to be able to produce|read more concise code, by reducing the ''code noise'' ``code noise`` of these 
 nested multiple ``end`` keywords with a shorter|cleaner syntax. 

 Thus, I propose creating the keyword ``ends`` as a shorter|cleaner syntax to replace having to write multiple ``end`` keywords. 

 #### Example 
 **Example** 

 Below is an example of real code which performs nested loops. With ''standard'' "standard`` format it looks like this. 

 ```ruby ``` 
 def render(scene, image, screenWidth, screenHeight) 
   screenHeight.times do |y| 
     screenWidth.times do |x| 
       color = self.traceRay(....) 
       r, g, b = Color.toDrawingColor(color) 
       image.set(x, y, StumpyCore::RGBA.from_rgb(r, g, b)) 
     end  
   end  
 end 
 ``` 

 However, from the point of view of the parser, these are all legal|equivalent. 

 ```ruby ``` 
 def render(scene, image, screenWidth, screenHeight) 
   screenHeight.times do |y| 
     screenWidth.times do |x| 
       color = self.traceRay(....) 
       r, g, b = Color.toDrawingColor(color) 
       image.set(x, y, StumpyCore::RGBA.from_rgb(r, g, b)) 
     end       end           end       end end end 
   end           end         end 
 end               end       end 
 ``` 

 This proposal would allow this type of code to be written writtn as: 

 ```ruby ``` 
 def render(scene, image, screenWidth, screenHeight) 
   screenHeight.times do |y| 
     screenWidth.times do |x| 
       color = self.traceRay(....) 
       r, g, b = Color.toDrawingColor(color) 
       image.set(x, y, StumpyCore::RGBA.from_rgb(r, g, b)) 
 ends 
 ``` 

 #### Pros 
 **Pros** 
 1) code conciseness 
 2) better readability 
 3) no whitespace dependencies 
 4) no conflict with legacy code 
 5) attractice to people coming from Python|Nim, et al 

 #### Cons **Cons** 
 No technical implementation restrictions I can think of. 
 Maybe alternative name (endall)? 

 Thanks for consideration. 

Back