Skip to content

Programming Basics

JessicaOPRD edited this page Dec 28, 2022 · 27 revisions

"String literal"/"literal string" is definitely burned into my brain. Some of these I generally know and use, others I often forget or only re-discover when learning a new language.

Definition Example Description
Method invocation operator object.method(arguments); Parenthesis in method invocation.
Member access operator object.method(arguments); Dot that navigates to class method.
End of statement operator object.method(arguments); Tells compiler the command is finished.
Literal value "Hello Galaxy" Hard-coded value that never changes. About presentation, not calculation.
Implicit type conversion int numberOfPets = '3' C# will output 51. However int cannot be assigned to string type implicitly unless used appropriately in concatenation.
Implicitly typed variable var numberOfPets = 3 The language attempts to interpret the type, often based on how it's set. For instance, 3 vs. '3'. In some languages (C#), an implicitly typed variable is typed and enforced base on the first declaration. But most languages allow various type declarations.
Assignment operator = Used to set variable values. In some languages you can only get a value if it's been set (not all support undefined).
Escape character sequence \t, \n, \\, etc. Special instruction to insert special character at runtime. I avoid these whenever possible in favor of other formatting approaches, but sometimes they are necessary.
Verbatim string literal @" ... " Preserves whitespace and characters. This varies a lot across languages. They are often limiting without string interpolation as well. It is common to combine verbatim string literals and string interpolation. C#: $@"..."
String concatenation operator &, +, etc. Used to concatenate two strings together. I typically try to avoid these as well, in favor of other techniques.
Intermediate variable var message = greeting + " " + firstName; Variable that's declared for the purpose of holding a concatenated or operated on value, but might have just as easily been printed or returned. Only add them if they improve readability.
String interpolation $"{greeting} {firstName}!", ${greeting} ${firstName} A string template with 1+ interpolation expressions. I use these all the time.
Overloading the operator 2 + 2 = 4 but '2' + '2' = '22' — also parenthesis used to invoke method, for order of operations, and casting (decimal) Reuse of a symbol for more than one purpose. This happens with + in C# and JavaScript, but not ColdFusion.
Compound assignment operators +=, -=, ++, -- For example addition assignment operator. Both compound and assign at the same time.
Stateless or static methods Math.random() Perform work without referencing or changing values already stored in memory. In most languages there is no need to create an object to execute the method. I learned these as "static" methods. Most languages have them, but ColdFusion does not. These methods tend to be "functional" in nature, but not always. They may do work on passed objects and return the same object (versus a new object). Generally there are no side effects except perhaps on input objects.
Stateful or instance methods new Promise( ... ).then( ... ) Perform work referencing values already stored in memory from previous lines of code or initialization. They track and maintain the state of an object and/or the application. Instance properties are fields.
Void methods public void function() { ... } No values are returned in the process of performing work. They are "quiet."
Method signature Number of input parameters AND data type per parameter.
Overloaded method Console.WriteLine Methods with multiple method signatures. I seem to recall ColdFusion does not allow method overloading. Java and C# do. In C# Console.WriteLine has 19 methods. This sounds exhausting to me.
Compound condition ((A == B) [Two pipes] (B == C)) Combined boolean expressions.
Logical OR operator [Two pipes] Either the expression on the left or the expression on the right. Aggregates two expressions so either subexpression can be true for the entire statement to be true.
Logical AND operator && Only if both expressions are true. Aggregates two expression so both subexpressions must be true for the entire statement to be true.