Common name for variable and constant - variables

In programming (and math) there are variables and constants. Is there a name to describe both of them?
I was thinking value, but that's not it. A value is what variables/constants contain, not what they are.

I would call it a symbol. From google:
sym·bol/ˈsimbəl/Noun
1. A thing that represents or stands for something else,
esp. a material object representing something abstract.
...

From what I know Its called a field

How about:
maths and logic: term
programming: l-value and r-value.

There are a few different terms I use, depending on context. I'll give you a list of the terms I (might) use - sometimes I'll just default to calling everything 'variables'.
Field - a variable or constant that's declared as part of the class definition.
Parameter - one of the inputs specified when defining a method in a class.
Argument - the actual value that you provide for a parameter when calling a method.
Method variable - a variable declared inside a method.
Method constant - a constant declared inside a method.

In OOP, the attribute can be both a variable and a constant.

Identifiers
In computer languages, identifiers are tokens (also called symbols) which name language entities. Some of the kinds of entities an identifier might denote include variables, types, labels, subroutines, and packages.
Symbols are super set of Identifiers
https://en.wikipedia.org/wiki/Identifier#In_computer_languages

How about "data item"?
One definition: https://www.yourdictionary.com/data-item
Example showing it can be used for local variables/constants as well (unlike "field" or "attribute"): https://www.microfocus.com/documentation/visual-cobol/VC222/EclWin/GUID-A3B817EE-1D63-4F67-A62C-61DE681C6719.html

Related

abap reference variables and dynamic types

I'm fluent in ABAP and have a grasp on OO and light reference variables, but can't seem to get a deeper handle on reference variables and dynamic types etc. I've done a bit of reading, but can't seem to get the deep understanding I feel I need.
Does anyone know of some great tutorials or websites that might give clear and concise? Thanks!
First of all just google this post title and You're golden.
Second:
I'm not sure if I understand You correctly, do You want to know about such constructions as:
DATA lo_ref_var TYPE REF TO zcl_my_class.
And by dynamic types do You mean in ABAP 7.4/7.5 (ex. DATA(lv_var) = 123)?
If yes, I'll try to give You the general idea:
Reference variable is just a variable that's "ready to become" an object.
If You'll take this for example:
DATA lo_ref_var TYPE REF TO zcl_my_class.
CREATE OBJECT lo_ref_var.
Then assuming the constructor doesn't need any variables You'll get an instance of zcl_my_class Class with all it's attributes and methods. Also if You have an abstract class zcl_abs_class as a super-class and zcl_sub_class1 and zcl_sub_class2 as it's non-abstract subclass' than:
DATA:
lo_abs TYPE REF TO zcl_abs_class,
lo_sub1 TYPE REF TO zcl_sub_class1,
lo_sub2 TYPE REF TO zcl_sub_class2.
CREATE OBJECT: lo_sub1, lo_sub2.
lo_abs ?= lo_sub1.
lo_abs ?= lo_sub2.
What You can do (as seen above) is cast a subclass object to the super-class reference variable since the subclass' inherits from zcl_abs_class.
For more, do some digging.
Dynamic types:
This is in fact very simple, all You need to remember is that a variable has to have a type when being created dynamically. So for example:
DATA(lv_text) = text-000.
DATA(lv_int) = 1.
Line with lv_text will not work (will not compile) since text-000 does not have a precise type.
The second line on the other hand will take the type I.
If one would like to decide which type to choose You can do this by writing:
DATA(lv_bukrs) = CONV bukrs( '1234' ).
You can even use the type that an already existing variable has by writing:
DATA(lv_bukrs2) = CONV #( lv_bukrs ).
since the "#" means "use the type of variable inside brackets".
Hope this will help You start :)

What are anonymous variables?

A program variable is an abstraction of a computer memory cell or collection
of cells. Programmers often think of variable names as names for memory locations, but there is much more to a variable than just a name.
In this case, what is an anonymous variable?
What does the below statement mean?
Variables without names are called anonymous variables.
Can you provide language specific examples for the same?
In C++, reference variable to const can be initialized by constant.
In this point, temporary variable is created in memory to grab the constant.
const int &ref = 3;
like this. so we can call this temporary variable to "anonymous variable".
Variables are where you store you values. 'Variable Name' is the usually the easiest (and more human-like) way to locate your value.For example, if I am a variable, you can get my value by calling my name, and the combination of my value and my name is called 'variable'.
However, not all variables need a name.Sometimes you just use them once and don't need them anymore; and in that case, a name is unnecessary.
The example given by #BAE HA RAM is a telling one,in which case you don't need a name for the value but ref to it by a pointer(But still got a name for that pointer)..
There are also many other anonymous things, anonymous type, anonymous function and so on. Most of them are created to avoid too many meaningless names for the things that you only need to run once.
I'd like to know which language you are using, so more specific example can be given...

Efficient method names for formulas?

I have a problem regarding method names. My project has the following folders Physics -> Equations -> Mechanics. This is where I intend to create classes with methods that allows me to calculate various equations. The problem lies with how to give those methods meaningful names that would explain their useage. To my knowledge each and every equation doesn't come with a name that helps us differentiate between them.
I tried to give my methods names according to their endresult and it seemed working just fine however there is a limit to overloading methods. My input variables are so far only doubles.
What is the best practice to this?
From Oracle Docs:
Naming a Method
Although a method name can be any legal identifier, code conventions
restrict method names. By convention, method names should be a verb in
lowercase or a multi-word name that begins with a verb in lowercase,
followed by adjectives, nouns, etc. In multi-word names, the first
letter of each of the second and following words should be
capitalized. Here are some examples:
run runFast getBackground getFinalData compareTo setX isEmpty
Typically, a method has a unique name within its class. However, a
method might have the same name as other methods due to method
overloading.
You can use parameter types in method name: ie.
DistanceBySpeedAndTime(double speed, double time);
DistanceByAccelerationAndTime(double acceleration, double time);

Correct Form for naming method parameters that clash with property names

If I have a class with a property of notificationCenter, and implement a method with this signature:
-(void)doSomethingWithNotificationCenter:(NSNotificationCenter *)notificationCenter
Xcode rightly gives me an error:
'local declaration of notificationCenter hides instance variable'
So in Objective C is there a convention for naming this parameter to avoid this collision?
The parameter should be called aNotificationCenter or possibly aCenter.
This seems like a personal preference, I have seen aNotificationCenter as mentioned above, inNotificationCenter, theNotificationCenter among others. I think as long as you are consistent in your own code any basic, readable choice is OK.
PS - my personal preference is inNotificationCenter.
I sometimes use the format receivedNotificationCenter or notificationCenterParam.

Ocaml naming convention

I am wondering if there exists already some naming conventions for Ocaml, especially for names of constructors, names of variables, names of functions, and names for labels of record.
For instance, if I want to define a type condition, do you suggest to annote its constructors explicitly (for example Condition_None) so as to know directly it is a constructor of condition?
Also how would you name a variable of this type? c or a_condition? I always hesitate to use a, an or the.
To declare a function, is it necessary to give it a name which allows to infer the types of arguments from its name, for example remove_condition_from_list: condition -> condition list -> condition list?
In addition, I use record a lot in my programs. How do you name a record so that it looks different from a normal variable?
There are really thousands of ways to name something, I would like to find a conventional one with a good taste, stick to it, so that I do not need to think before naming. This is an open discussion, any suggestion will be welcome. Thank you!
You may be interested in the Caml programming guidelines. They cover variable naming, but do not answer your precise questions.
Regarding constructor namespacing : in theory, you should be able to use modules as namespaces rather than adding prefixes to your constructor names. You could have, say, a Constructor module and use Constructor.None to avoid confusion with the standard None constructor of the option type. You could then use open or the local open syntax of ocaml 3.12, or use module aliasing module C = Constructor then C.None when useful, to avoid long names.
In practice, people still tend to use a short prefix, such as the first letter of the type name capitalized, CNone, to avoid any confusion when you manipulate two modules with the same constructor names; this often happen, for example, when you are writing a compiler and have several passes manipulating different AST types with similar types: after-parsing Let form, after-typing Let form, etc.
Regarding your second question, I would favor concision. Inference mean the type information can most of the time stay implicit, you don't need to enforce explicit annotation in your naming conventions. It will often be obvious from the context -- or unimportant -- what types are manipulated, eg. remove cond (l1 # l2). It's even less useful if your remove value is defined inside a Condition submodule.
Edit: record labels have the same scoping behavior than sum type constructors. If you have defined a {x: int; y : int} record in a Coord submodule, you access fields with foo.Coord.x outside the module, or with an alias foo.C.x, or Coord.(foo.x) using the "local open" feature of 3.12. That's basically the same thing as sum constructors.
Before 3.12, you had to write that module on each field of a record, eg. {Coord.x = 2; Coord.y = 3}. Since 3.12 you can just qualify the first field: {Coord.x = 2; y = 3}. This also works in pattern position.
If you want naming convention suggestions, look at the standard library. Beyond that you'll find many people with their own naming conventions, and it's up to you to decide who to trust (just be consistent, i.e. pick one, not many). The standard library is the only thing that's shared by all Ocaml programmers.
Often you would define a single type, or a single bunch of closely related types, in a module. So rather than having a type called condition, you'd have a module called Condition with a type t. (You should give your module some other name though, because there is already a module called Condition in the standard library!). A function to remove a condition from a list would be Condition.remove_from_list or ConditionList.remove. See for example the modules List, Array, Hashtbl,Map.Make`, etc. in the standard library.
For an example of a module that defines many types, look at Unix. This is a bit of a special case because the names are mostly taken from the preexisting C API. Many constructors have a short prefix, e.g. O_ for open_flag, SEEK_ for seek_command, etc.; this is a reasonable convention.
There's no reason to encode the type of a variable in its name. The compiler won't use the name to deduce the type. If the type of a variable isn't clear to a casual reader from the context, put a type annotation when you define it; that way the information provided to the reader is validated by the compiler.