Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

This is a repository for MathCase notation for naming variables taken from math equations.

License

NotificationsYou must be signed in to change notification settings

Leticia-maria/MathCase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

A new convention for naming variables taken from math formulas.

Tips for Creating Good Names for Variables

Since names are the smallest building block of code, they should follow some rules to be good.

  • Use intention-revealing names
  • Avoid disinformation
  • Make meaningful distinctions
  • Use pronounceable names
  • Use searchable names
  • Avoid encondings
  • Avoid mental mapping

But, when we are talking about math formulas, some of these rules are difficult to follow. For example, take a look at this code:

foriinrange(n):forjinrange(m):forkinrange(l):temp_value=X[i][j][k]*12.5new_array[i][j][k]=temp_value+150

If you were trying to modify or debug this code, you'd be at a loss unless you could read the author's mind. Even if you were the author, a few days after writing this code you might not remember what it does because of the unhelpful variable names and use ofmagic numbers.

Looking at scientific programming codes, it is often to see examples like above (or worse): code with variable names such asX,y,xs,x1,x2,tp,tm,cif,reg,xi,yi,ii and numerous unnamed constant values.

What Makes a Bad Variable Name?

Summarizing that, most problems with naming variables stem from:

  • A desire to keep variable names short
  • A direct translation of formulas into code

On this first point, while languages like Fortran did limit the length of variable names (to six characters), modern programming languages have no restrictions so don't feel forced to use contrived abbreviations. But it is not recommended to use long variable names (always thinking aboutreadability).

Let's see an example that makes both mistakes. Say we have a polynomial equation for finding the price of a house from a model. You may be tempted to write the mathematical formula directly in code.

y = m_1 * x_1 + m_2 * x_2^2 + b

temp=m1*x1+m2* (x2**2)final=temp+b

This code looks like it was written by a machine for a machine. While a computer will ultimately run your code, it'll be read by humans, so write code intended for humans. To do this, we need to think not about the formula itself (the how) and consider the real-world objects being modeled (the what). Then, rewriting the last example:

house_price=price_per_room*rooms+ \price_per_floor_squared* (floors**2)house_price=house_price+expected_mean_house_price

About

This is a repository for MathCase notation for naming variables taken from math equations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp