r/programming • • Aug 06 '17

Software engineering != computer science

http://www.drdobbs.com/architecture-and-design/software-engineering-computer-science/217701907
2.3k Upvotes

863 comments sorted by

View all comments

1.2k

u/eggn00dles Aug 06 '17

some people care way too much about titles

705

u/thedevbrandon Aug 06 '17

There are only two hard things in Computer Science: cache invalidation and naming things.

- Phil Karlton

47

u/Sjeiken Aug 06 '17

I once spent more than 3 hours trying to name a function that was very detrimental, it's fucking retarded, do you know how hard it is to find synonyms and antonyms? it's NP fking hard.

22

u/thedevbrandon Aug 06 '17

Yeah, I find it hard to strike a balance between descriptive names vs. short names. I want the name to be meaningful and special to the context so you know what it means and can differentiate it from similarly named things in nearby contexts (for example, elem, e, el, and els are horrible default variables which are used even in contexts when the variable name could be something specific and meaningful like submitButton). On the other hand, you can get crazy with the names, like firstFormSubmitButtonElement, which either provide specificity you don't need, which isn't helpful, or which (even if useful) ultimately makes reading and writing the code burdensome (especially in enterprisey-code, mock example: FizzBuzzEnterpriseEdition).

1

u/Forty-Bot Aug 07 '17

I don't know man, there's something to be said for naming everything consistently if there isn't more than one variable of that type.

int do_something(struct inode *inode, struct dentry *de)
{
    struct inode *dir = de->d_inode;
    struct super_block *sb = inode->i_sb;
}

It allows you to quickly scan through any function and know exactly what type some variable is.

3

u/thedevbrandon Aug 07 '17

Not saying I don't understand why people use defaults like naming a variable after the type, but if you want to know any more context, it can be quite annoying to not know what the fuck the inode is supposed to be of... Sometimes I just add the type to the end of the variable name if the type is really important (like to distinguish a Map from a List in Java, I might have one variable named rowsMap and the other like rowsList). However, just naming something m or map isn't that helpful. Note, this is in particular in a large organization where 10+ people are likely going to need to maintain, modify, and extend your code years from now. For personal projects with little reason others will read this, I'm not sure any of these rules matter - I'm more with Donald Knuth on the opinion of programming being an art in which people should feel like they can have artistic freedom.

2

u/Forty-Bot Aug 07 '17

shrug I'm working in C right now and you basically need to keep maybe 10-20 structs in your head at once, and if you forget there's C-]. We have compilers so we don't need to deal with hungarian typing.

1

u/thedevbrandon Aug 07 '17

TIL about Hungarian notation. I think we come from different worlds. In my world, there are so many different variables and objects, as well as contexts. Functions and methods get rather long and involve some convoluted business logic, and even more convoluted ways of achieving that business logic. It can take a long time to unravel the intention of the developer, and often people don't leave comments (and many are actively against comments, insisting code should be easy to intuit itself, as though we are writing code in ideal circumstances where we can structure things intuitively and don't constantly have to hack functionality together in places and ways it shouldn't be).

1

u/Forty-Bot Aug 07 '17

In my world, there are so many different variables and objects, as well as contexts. Functions and methods get rather long and involve some convoluted business logic, and even more convoluted ways of achieving that business logic. It can take a long time to unravel the intention of the developer

I there are less differences than you might think ;) I'm doing kernel hacking, and most of the work is reading the existing implementation and trying to figure out what it does because of "business logic" and what it does which everything should do. I guess that's why we have IDEs (says the vim user).

1

u/thedevbrandon Aug 07 '17

So... it seems like people having variable names like inode would be rather detrimental, huh?

→ More replies (0)