Learning Ruby on Rails w ChatGPT for Credibull

So in order to harness AI for credibull.org I thought I would learn a “modern” web backend language – Ruby. Mainly as Derek Sivers swears by it, and it is a good power house of a language, which should translate to a community supporting it in the future easily.

So… first deciding if I should run Linux or run Ruby on Windows – I am just setting it up on Windows for now. I am keen to move to Linux, and I am not far off dumping Microsoft, Google and Adobe, but is a little way down the geek track, even for me.

To share and document the process, ChatGPT has suggested I look out here

When starting with Ruby, here are ten common mistakes that newcomers often make due to naivety:

  1. Misunderstanding Variable Scope: Ruby has different variable scopes, such as local, instance, and class scopes. It’s important to understand how scope works to avoid unexpected behavior and ensure proper variable access.
  2. Forgetting to End Statements: In Ruby, statements like conditionals and loops require an end keyword to close them. Forgetting to add the necessary end can lead to syntax errors and unexpected code behavior.
  3. String Interpolation: In Ruby, string interpolation allows you to embed expressions within double-quoted strings using #{}. Newcomers may mistakenly use single quotes or forget the correct syntax, resulting in literal string output instead of the desired interpolated values.
  4. Mutating Immutable Objects: Ruby differentiates between mutable and immutable objects. Immutable objects, such as strings and numbers, cannot be modified directly. Attempting to modify them can lead to unintended consequences. Understanding object mutability is crucial to avoid unexpected behavior.
  5. Using Wrong Comparison Operators: Ruby provides different comparison operators (==, ===, !=, <=, <=>, etc.) with specific meanings. Using the wrong operator or misunderstanding their behavior can lead to incorrect logic and faulty code.
  6. Confusion with Block vs. Proc/lambda: Ruby uses blocks, Procs, and lambdas for functional programming. Understanding the differences between them and when to use each can be challenging for beginners, leading to errors and unexpected behavior.
  7. Misusing Global Variables: Ruby has global variables, but it’s generally considered good practice to avoid them. Misusing global variables can introduce unexpected side effects and make code harder to maintain. Prefer local variables or other appropriate scoping mechanisms.
  8. Ignoring Error Handling: Neglecting proper error handling using begin, rescue, ensure, and raise can result in unhandled exceptions and unexpected program termination. Always consider error scenarios and handle them appropriately to ensure robust code.
  9. Modifying Objects During Iteration: Modifying an object (e.g., an array or hash) while iterating over it can lead to unpredictable behavior. It’s best to avoid modifying the collection being iterated and use techniques like creating a separate modified copy if needed.
  10. Neglecting Testing: Skipping testing and not following a test-driven development approach can make code harder to debug and maintain. Writing tests helps catch bugs early and provides a safety net when making changes or refactoring code.

These are just a few examples of common mistakes, but with practice, attention to detail, and continuously learning from the Ruby community and resources, you’ll become more proficient and avoid these pitfalls.

I have setup my environment with Ruby on Windows, Vim and all command prompt ready to rumble!
I also have a batch file in PATH that converts “ls” command to “dir” so is a good first step to moving to a Linux Life.



Leave your reply

The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notice: Function WP_Scripts::localize was called incorrectly. The $l10n parameter must be an array. To pass arbitrary data to scripts, use the wp_add_inline_script() function instead. Please see Debugging in WordPress for more information. (This message was added in version 5.7.0.) in /var/web/site/public_html/wp-includes/functions.php on line 5905