What is the correct terminology for "->", ie $class->method() - terminology

$class->method()
^
|
What's the correct terminology for this?

I've always called the symbol an "arrow".

Depends on the language:
-PHP, I believe its just used to access a class members
-C or C++ on the other hand, it is used to derefernce a pointer and access a member. It's pretty much just syntactic sugar.
pointer->member
is equivalent to
(*pointer).member

I believe that's called the "arrow notation", assuming of course you are talking about PHP. Thats what most publications, articles and the PHP website call it, so that's what my brain says on sight.

Member access operator.

I think C++ calls it “pointer member access operator.“

i would say: dereference operator
see: http://en.wikipedia.org/wiki/Dereference_operator
after some discussions with good commenters, the final terminology could be:
dereference and field access operator
that could be shorten into:
- field access operator

It's the "member selection" operator or "member by pointer" operator.
MSDN Library: C++ operators
Wikipedia: C++ opreators

In PHP it is called the T_OBJECT_OPERATOR. See the List of Parser Tokens in the PHP Manual.

Related

What does 'Language Construct' mean?

I am learning C from 'Programming in C' by Stephen Kochan.
Though the author is careful from the beginning only not to confuse the students with jargon, but occasionally he has used few terms without explaining their meaning. I have figured out the meaning of many such terms with the help of internet.
However, I could not understand the exactly meaning of the phrase 'language construct', and unfortunately the web doesn't provide a good explanation.
Considering I am a beginner, what does 'language construct' mean?
First, you need to understand what a constructed language Formal Language is. All programming languages are constructed formal languages (read the reference). You may then read a little bit about compiler construction, including this reference as well.
Going back to your question, consider this: The English language (a natural language) has tokens 'A-Z/0-9/,;"...' which we use to build "words" and we use languages rules to build sentences out of words. So, in the English language, a construct is what we build out of tokens.
Consider this brick-and-mortar example: Imagine if you set out to build a house, the basic materials you might use are: sand, iron, wood, cement, water (just five for simplicity). Anything you build out of these 4 or 5+ items would be a "construct", which in turn helps you build your house.
I have intentionally omitted details to further simplify the answer; hope this is helpful.
A language construct is a piece of language syntax. For example, the following is a language construct in C that lets you control the flow of a program:
if ( condition ) {
/* when condition is true */
} else {
/* when condition is false */
}
They usually use the term language construct because these are parts of most programming languages, but may be written differently, depending on the language. For example, a similar language construct in bourne shell would be:
if COMMAND; then
# when command returns 0
else
# when command returns anything else
fi
The function of this construct is the same, however, the way it's written is a bit different.
Hope this helps. If you need more detail, you may want to do a bit more research. As one of the comments suggests, Wikipedia may be helpful.
They are the base units from which the language is built up. They can't be used as a function rollback. They are directly called by the parser.
It includes all the syntax, semantics and coding styles of a language.
For more clarification you may refer to this question.
Wikipedia definition:
A language construct is a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language.
The term Language Constructs is often used as a synonym for control structure, and should not be confused with a function.
Without seeing the context that the phrase is used in, I cannot be sure, but generally the phrase 'language construct' just means the combination of keywords, grammar and structure of a coding language. Basically, how to format/write/construct a piece of code.
Let say you want to create a class containing methods and properties, so:
Construct is an architecture of a class you are about to create. The architecture of the class consists of methods and properties created by you by using predefined utilities (such as: 'if', 'else', 'switch', 'break', etc)
That's my take on construct.
In reference to a programming language
Language Constructs mean the basic constructs of a programming languge e.g
1. Conditions (if, else, switch)
2. Loops (For, While, Do-while) etc
C is a structural language so while compiling your code everything thing goes statement by statement. Thus it becomes necessary to place your statement properly. This placing i.e. putting your statement correctly is your language construct else there may be syntax error or logical error.
Language constructs according to the GCSE book are basic building block of a programming language. that are
1. Sequential,
2. Selection, if, if/else
3. Iteration, while, for
Language construct is a piece of language syntax.
Example:
A declaration of a variable is a language construct:
{
int a; // declaration of a variable "a"
}
A language construct is a piece of syntax that the compiler has intimate knowledge about, usually because it needs to handle it specially. Typical examples of language constructs are the short-circuiting operators found in many imperative languages. Because these operators require lazy evaluation in an otherwise eager language, they must be handled specially by the compiler.
So, a stricter definition of a language construct may be: a syntactical form that is handled specially by the compiler, having functionality that cannot be implemented by a user.

Formal syntax for function/variable definition

I remember somewhere seeing such a notation for formally defining a variable:
variable_name: type
And similarly:
function_name(....): return_type
But I don't remember and I can't find the formal definition of this syntax.
My question first is, is this really a formal syntax or did somebody just make it up? My second question, can you give me the name for it, or a reference?
I am asking because I was wondering how the function arguments are defined. Would it be like this?
function(arg1:type1, arg2:type2): type
If so, how are default values shown?
The syntax you describe is used in the ML family of programming languages. In Standard ML, which has a formal semantics, there are no default values, everything must be initialized when declared.

Is there a programming language with no controls structures or operators?

Like Smalltalk or Lisp?
EDIT
Where control structures are like:
Java Python
if( condition ) { if cond:
doSomething doSomething
}
Or
Java Python
while( true ) { while True:
print("Hello"); print "Hello"
}
And operators
Java, Python
1 + 2 // + operator
2 * 5 // * op
In Smalltalk ( if I'm correct ) that would be:
condition ifTrue:[
doSomething
]
True whileTrue:[
"Hello" print
]
1 + 2 // + is a method of 1 and the parameter is 2 like 1.add(2)
2 * 5 // same thing
how come you've never heard of lisp before?
You mean without special syntax for achieving the same?
Lots of languages have control structures and operators that are "really" some form of message passing or functional call system that can be redefined. Most "pure" object languages and pure functional languages fit the bill. But they are all still going to have your "+" and some form of code block--including SmallTalk!--so your question is a little misleading.
Assembly
Befunge
Prolog*
*I cannot be held accountable for any frustration and/or headaches caused by trying to get your head around this technology, nor am I liable for any damages caused by you due to aforementioned conditions including, but not limited to, broken keyboard, punched-in screen and/or head-shaped dents in your desk.
Pure lambda calculus? Here's the grammar for the entire language:
e ::= x | e1 e2 | \x . e
All you have are variables, function application, and function creation. It's equivalent in power to a Turing machine. There are well-known codings (typically "Church encodings") for such constructs as
If-then-else
while-do
recursion
and such datatypes as
Booleans
integers
records
lists, trees, and other recursive types
Coding in lambda calculus can be a lot of fun—our students will do it in the undergraduate languages course next spring.
Forth may qualify, depending on exactly what you mean by "no control structures or operators". Forth may appear to have them, but really they are all just symbols, and the "control structures" and "operators" can be defined (or redefined) by the programmer.
What about Logo or more specifically, Turtle Graphics? I'm sure we all remember that, PEN UP, PEN DOWN, FORWARD 10, etc.
The SMITH programming language:
http://esolangs.org/wiki/SMITH
http://catseye.tc/projects/smith/
It has no jumps and is Turing complete. I've also made a Haskell interpreter for this bad boy a few years back.
I'll be first to mention brain**** then.
In Tcl, there's no control structures; there's just commands and they can all be redefined. Every last one. There's also no operators. Well, except for in expressions, but that's really just an imported foreign syntax that isn't part of the language itself. (We can also import full C or Fortran or just about anything else.)
How about FRACTRAN?
FRACTRAN is a Turing-complete esoteric programming language invented by the mathematician John Conway. A FRACTRAN program is an ordered list of positive fractions together with an initial positive integer input n. The program is run by updating the integer (n) as follows:
for the first fraction f in the list for which nf is an integer, replace n by nf
repeat this rule until no fraction in the list produces an integer when multiplied by n, then halt.
Of course there is an implicit control structure in rule 2.
D (used in DTrace)?
APT - (Automatic Programmed Tool) used extensively for programming NC machine tools.
The language also has no IO capabilities.
XSLT (or XSL, some say) has control structures like if and for, but you should generally avoid them and deal with everything by writing rules with the correct level of specificity. So the control structures are there, but are implied by the default thing the translation engine does: apply potentially-recursive rules.
For and if (and some others) do exist, but in many many situations you can and should work around them.
How about Whenever?
Programs consist of "to-do list" - a series of statements which are executed in random order. Each statement can contain a prerequisite, which if not fulfilled causes the statement to be deferred until some (random) later time.
I'm not entirely clear on the concept, but I think PostScript meets the criteria, although it calls all of its functions operators (the way LISP calls all of its operators functions).
Makefile syntax doesn't seem to have any operators or control structures. I'd say it's a programming language but it isn't Turing Complete (without extensions to the POSIX standard anyway)
So... you're looking for a super-simple language? How about Batch programming? If you have any version of Windows, then you have access to a Batch compiler. It's also more useful than you'd think, since you can carry out basic file functions (copy, rename, make directory, delete file, etc.)
http://www.csulb.edu/~murdock/dosindex.html
Example
Open notepad and make a .Bat file on your Windows box.
Open the .Bat file with notepad
In the first line, type "echo off"
In the second line, type "echo hello world"
In the third line, type "pause"
Save and run the file.
If you're looking for a way to learn some very basic programming, this is a good way to start. (Just be careful with the Delete and Format commands. Don't experiment with those.)

How do you work around the need for apostrophes in certain function names?

When I'm programming, I often find myself writing functions that -should- (to be proper english) contain apostrophes (too bad C started everyone thinking that an apostrophe was an appropriate delimiter). For example: get_user's_group() -> get_users_group() . What do you guys do with that forced-bad-english ambiguous english? Just ignore the apostrophe? Create a different phrasing?
In that case, I would do get_group_for_user().
So, yes, I would "create a different phrasing" :)
Either that, or user.get_group().
getGroupForUser()
or
getGroupByUser()
My original answer of Ignore it, move on! is incomplete. You should ignore the fact you can't use ' in your method/function names. But you should continue to look at the naming of them to better explain what they do. I think this is a worthwhile pursuit in programming.
Picking on JavaScript, you could if you wanted to use apostrophes:
const user = {
"get_user's_group": () => console.log("Naming things! Am I right?!")
}
user["get_user's_group"]()
But don't do that 😬
Taking it further, you could if you wanted to, use a transpiler to take your grammatically correct name and transform it into something you never see.
Again with JavaScript as an example, maybe you could write a babel transform.
But don't do that 😛
As others have said, if there is context available from an object, that's a nice option:
user.get_group()
Failing that, the context of the surrounding code should be enough to make this your choice:
get_users_group()
How about getGroupByUser?
Either get_user_ApostropheShouldBeHereButLanguageWillNotLetMe_s_group or just ignore it because it really doesn't matter.
I ignore the apostraphe getGroupyUser and group_from_user are both perfectly understandable. Worrying about having correct grammer in your function names is a waste of time and distracts from the correct goal of having clear and understandable user names.
the point of proper english in function naming is a bit extreme ...
i mean why is the apostrophe bothering you but the _ instead of a space is not ?
Depending on the programming language you may be able to use Unicode variable names, this SO thread lists a few.
With Unicode identifiers you could use one of the unicode apostrophes to give the proper english language formatting to your variable name. Though this only speculative. And it would be hard to maintain. Actually, now that I think about it, it sounds downright evil.
Two points: First, don't use a name that would otherwise require an apostrophe if you can avoid it. Second, you are right in being concerned about ambiguity. For example, you could have:
getUsersGroup: gets the group of a list of users. If you are using an object-oriented language, this could have more information than just a group ID string. You could also have something like createUsersGroup, which would create a group object from a list of users passed in.
getGroupOfUser: takes in some sort of user object; returns the name of the group of the user
getGroupByUserId: takes in the user's name or a unique ID associated with that user; returns the name of the group of the user
The best way to delineate the difference between all of these is to just use standard method comments that explain the method names. This would depend on what language you are working with and what style of method comments your organization conventionally uses.
Normally I just drop the apostrophe, but do back-ticks work? (get_user`s_group)
getGroupOfUser? getUserGroup?
It's a programming language, not literature...
It would be getBackgroundColour in proper English (rather than getBackgroundColor)
Personally I'd write get_user_group() rather than get_group_for_user() since it feels like it reads better to me. Of course, I use a programming language where apostrophes are allowed in names:
proc get_user's_group {id} {#...}
Although, some of the more prolific non-English-native European users use it as a word separator:
proc user'group {id} {#...}
to each his own I guess..

How to execute a literal in VBA?

Is there a way to execute a literal such as,
UseValueKey = ExecuteMethod("Date()")
I want to have the variable UseValueKey return the actual date.
I am using VBA.
Any ideas?
I haven't done any VBA coding for several years, but I recall that Access VBA had an Eval() method that could be used to evaluate code represented as a string.
This article gives an example of its usage.
You can try the Eval function.
If, as indicated in the question comments, the function name is known and can be delivered as a method on a class, try looking at
CallByName object, routine, callType
where callType indicates whether the called routine is a property Get/Let/Set or a Method.
It feels a lot less kludgey (and somewhat better controlled) than fooling with code evaluation, where you may be leaving yourself open to, er, unexpected consequences...
Perhaps I'm not exactly following you, but you should be able to use
Date
for example
UseValueKey = date