Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Readibilty and ruby code style

Ruby have a lot of tricks to reduce the code you write... but... in that sense is like perl and have is own set, and a lot of people hates perl(not me), specially that offuscation capacietes.

I dont know if ruby can have that offuscated code, anyway. But what im wondering is... ¿what features of ruby language to use?

For example you dont need to write return each time, because it autoreturns the last value used. Thats very strange compared to anything other.

A other thing thats seems somewhat bad is to not use the () for call functions. If the program writed call functions with a different color it will be better, but i take time to understand these things and ever have been this type of difference between function and variable...

You have discovered some clever ruby tricks, also?
 
Of course there are ternery shorthands. myvar = x ? 3 : 0;
Then, there's the array shortcut. %w(one two three) will return ["one", "two", "three"] More useful for long word arrays, as it cuts down the "s and ,s. From what I understand it comes at a very slight performance cost, but this is negligible.

Then, of course, there's this:
http://caiustheory.com/ruby-shortcuts
 
There's the "unless" keyword, which confused me a lot when I was learning Ruby, although it actually can improve readability sometimes. And speaking of conditionals, there's the post-statement conditional, like "return 42 unless foo == bar". :shades:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top