Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This is more of a style question, but it is something I am currently pondering for a project of mine.

Assume that you're creating an application which is modeling a school. So there are entities like Student, School, etc. Now this is all fine and intuitive until you get down to Class, as (in most languages) Class is a reserved word. So, given that Class is a reserved keyword, what would you call such an entity that models a school class?

share|improve this question

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

16  
SchoolClass???? –  Matthew Flynn Mar 1 '12 at 4:43
5  
You could try a synonym thesaurus.com/browse/class –  Gary Buyn Mar 1 '12 at 4:49
    
@MatthewFlynn, that did indeed cross my mind. In fact, it was my first though... –  Jason Whitehorn Mar 1 '12 at 5:39
1  
I've reopened the question. Answers that re-iterate other answers or are snarky one-liners will be deleted, same for off topic comments. –  Yannis Rizos Mar 5 '12 at 14:40
1  
It's a completely legitimate question: "What do you do when your domain-specific term clashes with a term in your chosen programming language". It was just couched in the terms of a specific example, which is fine. –  Steve Bennett Mar 7 '12 at 0:07

8 Answers 8

up vote 33 down vote accepted

I'd pick another term because the word Class can be ambiguous.

Does class refer to:

  1. The group of students taking a course?
  2. The whole course for this semester?
  3. The abstract course taught in multiple semesters?
  4. The group of students expected to graduate at a specific time?
  5. Some other classification of students, i.e. Advanced Class, Special Needs class.
  6. A specific lecture

And that's without even leaving the academic realm. Chances are you can find a better word to fit whatever you are trying to model. Class will only lead to some confusion.

share|improve this answer
    
Ah, yes... very good points. This is the type of discussion I was looking for. I did, in fact, mean "A group of student taking a specific course taught by a specific teacher at a specific time for a single school term (year, semester, etc)"... if that makes any sense. Or, in other words, "I am taking Biology II with Mr. Smith @ 2pm Mondays, Wednesdays, Fridays." –  Jason Whitehorn Mar 1 '12 at 5:46
    
The general problem of established domain terms clashing with language keywords does remain though... –  tdammers Mar 1 '12 at 6:30
    
In some institutions that's called a Stream. (Which has its own name clash issues :)) –  Steve Bennett Mar 7 '12 at 0:01

You could name it a "Course," or a "Subject," or a "Lecture" if it is a specific class. You could also use "Section," etc.

Winston Ewert really highlighted the questions you would have to ask yourself.

share|improve this answer
    
+1 for Section. This seems to be what @JasonWhitehorn had in mind, based on his response to Winston Ewert's answer –  sq33G Mar 1 '12 at 9:13

Finding a synonym is a good idea, e.g "Course."

However, the need to reuse the word class is common (often for a local variable of type Class), and the conventional replacements for class include klass, clazz, and cls.

share|improve this answer
    
"klass" means you are German (or Dutch), "clazz" is more like "jazz" and "cls", oh, wasn't this used for "CLearScreen" ? –  ypercube Mar 1 '12 at 13:01

It depends, in some languages class is the reserved word, not Class.

share|improve this answer
4  
I did, however, say "...given that Class is a reserved keyword...", plus, wouldn't you say that two items differing only by case is a horrible idea? –  Jason Whitehorn Mar 1 '12 at 5:38
    
Doesn't mean you should use it. Any more than you should use If, Else or Goto in a language where the lower-case versions of these are reserved. –  David Wallace Mar 1 '12 at 5:39
5  
This is not an answer. –  Jordan Mar 1 '12 at 6:11
1  
Java already has a class Class. –  dan04 Mar 1 '12 at 6:13
3  
@JasonWhitehorn: two items differing only by case is not necessarily a bad idea at all – if all your classes have uppercase names while all keywords in your language are lowercase, it's completely unambiguous that Class is a custom-defined class. –  leftaroundabout Mar 1 '12 at 12:22

In some programming languages you can use reserved words in the variable names (possibly even class names?). For example in C# you could do like this even though class is a reserved word:

string @class = "Super class";

You could check your programming language specs does it allow you to do this.

If not then just go with Winston Ewerth's answer.

share|improve this answer

Aside from programming language syntax, the word class is not a good name from data modeling perspective in the case of a school information system. When you think about what a class means you find that (among other things):

A class is an regularly scheduled activity that has a start and end and is supervised (taught) by a school educator. Within this activity a subject is taught or an activity (like sport) is performed, so, a subject is offered as zero, one or more classes.

So the word class is really a "Scheduled Educational Activity" So you have the choic of:

  • ScheduledEducationalActivity

  • ScheduledActivity (in which case you can be more generic and allow the activity to be educational or an event like a lecture or a seminar or a tournment,...etc.)

  • SubjectOffering

So the name class really is a convention or (a business name) but is not the best name that describes the entity.

share|improve this answer

I am agree with @Winston Ewert that I'd pick another term because the word Class can be ambiguous.

In this case you have to use better synonym that suit your implementation. If i do model the such type of architecture then i shall go for Course, but there are other synonym also available can be used..

Check a example class architecture that somewhat match to your system. Ref: Student class and Course class

As your question tagged with the naming, use a noun or noun phrase to name a class from synonym that you use.

share|improve this answer

You could declare the entity as ClassRoom!

share|improve this answer
2  
That would be a bad name, unless the entity represents the physical room where the class is to be held. –  Jesper Mar 13 '12 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.