Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C class naming convention vs Uncle Bob

In Chapter 2: Meaningful Names Uncle Bob writes:

Don't Add Gratuitous Context

In an imaginary application called "Gas Station Deluxe," it is bad idea to prefix every class with GDS. Frankly, you are working against your tools. You type G and the press completion key and are rewarded with a mile-long list of every class in your system

Actually that what I discovered during my first days with Objective-C a bit more than one year ago. After Java it was quite disappointing but I thought I'm only one who annoyed about that :) I understand, that "Clean Code" book refers to Java most of the time and Java has namespaces (packages) unlike Objective-C.

Do you use 2-3 letters prefix in your classes if you're building an app, not a library? What do you think, is it bad language design, language "feature" or Uncle Bob wasn't right here?

like image 456
OgreSwamp Avatar asked Mar 06 '12 13:03

OgreSwamp


1 Answers

Perhaps the key word here is gratuitous. In Objective-C, prefixes serve the important purpose of reducing the chance of name collisions. In other languages like Java and C++, the existence of support for namespaces makes the use of prefixes gratuitous (and a violation of the oft-cited DRY principle). In Objective-C, however, prefixes are meaningful, useful, and not gratuitous.

like image 137
Caleb Avatar answered Sep 27 '22 00:09

Caleb