Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:01:20+00:00 2026-06-12T06:01:20+00:00

Having recently started programming in Ruby, I noticed one small language feature that is

  • 0

Having recently started programming in Ruby, I noticed one small language feature that is really giving me a hard time — variables that start with a capital letter are automatically constants.

While I understand that this is by design, and does really help in most cases, it becomes a problem once one starts writing algorithms. By that I mean code that requires efficient and easy distinction between variables — say, n and N.

Here is a very simplistic example (I’m aware it’s not a fully valid/rubyesque code, but I hope it illustrates my point):

def average(array)
  N = 0
  array.each { |n| N += n }
  N/array.length.to_f
end

Another example is subscripts — say, while doing a calculation in a physics problem, having F_friction and F_weight would be helpful but impossible in Ruby.

So, the question is: is there an accepted way of dealing with these variable names?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:01:21+00:00Added an answer on June 12, 2026 at 6:01 am

    Usually the solution is just to choose much more meaningful names. E.g.

    def average(values)
      total = 0
      values.each { |value| total += value }
      total/values.length.to_f
    end
    

    Why is F_weight helpful. F is for Force?

    Fine force_weight, erm no: force_mass. After all weight is a force.

    Now if you were talking about N as in the set of natural numbers, I could see some point if N wasn’t a local variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A have a Perl cron job that recently started having its HTTPS connections start
I recently started reading OpenGL Superbible 5th edition and noticed the following: Having just
I've just recently started programming for the iPhone and I'm making an application that
I've recently started using CMake for one of my multi-platform projects, but I'm having
I've recently started using Git and am having trouble with just one thing. How
I recently started working on a small personal project in Ruby on Rails, and
I've recently started learning and exploring the basics of GUI programming in Java. Having
I've recently started having trouble logging into my site using Facebook. I keep seeing
I started working on CodeIgniter recently and I'm having some issues with the .htaccess
Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.