Valid Variable Names: Rules & Tests

  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    Variable
Click For Summary

Discussion Overview

The discussion focuses on the rules for valid variable names in programming languages, specifically addressing how to identify reserved names during tests. Participants explore the challenges of recognizing reserved words without a provided list and the implications for learning programming languages.

Discussion Character

  • Debate/contested
  • Technical explanation

Main Points Raised

  • Some participants express uncertainty about how to spot reserved names in test questions without a list of reserved words.
  • One participant suggests that different programming languages have different sets of reserved words, implying the need for specificity in the discussion.
  • Another participant argues that if a test provides a list of reserved words, it would not effectively assess knowledge of the programming language.
  • A participant mentions that the C programming language has a short list of keywords that are all lowercase, providing a reference to the C standard for context.
  • One participant highlights the advantage of using an integrated development environment (IDE) for coding, as it visually distinguishes reserved words, making them easier to identify.
  • There is a suggestion that memorizing or keeping a list of reserved words is necessary if an IDE is not available.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to identifying reserved names in tests, and multiple views on the necessity of memorization versus the use of IDEs are presented.

Contextual Notes

The discussion does not resolve the specifics of how to effectively learn and identify reserved words across different programming languages, nor does it address the implications of case sensitivity.

Deathfish
Messages
80
Reaction score
0
Hi all, I would like to clarify regarding valid variable names. Well what I fairly understand are the rules regarding names.. What I am unsure about is -- in a test, is there any way to spot a reserved name? For example to make things difficult, trick question, sometimes the question will include

main
print
System
Int

etc. usually in a test we don't have the list of reserved words
 
Technology news on Phys.org
Deathfish said:
Hi all, I would like to clarify regarding valid variable names. Well what I fairly understand are the rules regarding names.. What I am unsure about is -- in a test, is there any way to spot a reserved name? For example to make things difficult, trick question, sometimes the question will include

main
print
System
Int

etc. usually in a test we don't have the list of reserved words

You need to be a bit more specific. What language are you asking about? Different languages have different sets of reserved words that can't be used as variable names.
 
Regardless of the programming language, if they gave you the list of reserved words and ask you to spot them in the list, that wouldn't be much of test, would it? If you are supposed to be learning a programming language, I presume they expect you to study its reserved words and memorize them; also, to be aware whether the programming language is case-sensitive or not.
 
Looks like C to me.

The list of keywords/reserved words in C is short. All of them are lowercase. The C standard (C11)
from what is usually called N1570:
N1570 Committee Draft — April 12, 2011 ISO/IEC 9899:201x:
6.4.1 Keywords
Syntax
1 keyword: one of
auto ∗
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
inline
int
long
register
restrict
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
_Alignas
_Alignof
_Atomic
_Bool
_Complex
_Generic
_Imaginary
_Noreturn
_Static_assert
_Thread_local
 
One reason programmers like to use an integrated development environment, or IDE, (rather than a simple command window) when writing code, is that the IDE's code window will highlight reserved words in a different color, so it is immediately apparent.

If it isn't possible to get an IDE or syntax-highlighting editor for you language, then you must simply memorize (or keep a list of handy) that language's reserved words. There can be a lot of them, so an IDE is the best solution if you can get it.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 89 ·
3
Replies
89
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
16
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K