• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Unmaintainable Code

thornc

Golden Member
This article is one of the greatest guides I have ever read on what you should not do when your programming....

In fact I think every aspering programmer should read it carefully!!
 
🙂

Every CS student should be forced to do some maintenance programming, preferably working with both clean code and code that follows this guide. Then more will appreciate why bashing out code as fast as possible now will come back to bite them later.
 
Yeah, I agree. But the only problem with making everything easy to update and all that is time usually forces you to hurry the f up and the first thing you want to do id get it up an running. Sad but true. Clients and non-porgrammers don't care about the code, they just want it done fast. So many times I myself and others, I am sure, get stuck with little to no comments, functions which aren't written great and stuff all over the place. Sure in the long run this is a bad move but clients don't usually think of that.
 
I have the pleasure of working with a few people right now who are *very* good at doing the exact opposite of what that page describes. OOP, specific language strengths, refactoring, descriptive, verbose naming, all go very far to make code alot more elegant and less buggy.
 
Glad to hear that there people out there that understand the need to write "Solid Code" in every go.

The excuse of not having enough time doesn't convince me.... there's a rule from a book I once read that I have applied ever since. The find out the time a project is going to take to be finished, take your first estimate for the design time and double it, take your first estimate for the implementation time and multiply it by 10, take your first time estimate for debugging and testing and triple it; add everything togheter and double it again. The result should be enough to make the project in time! (Barely 🙂 )
 
Originally posted by: thornc
Glad to hear that there people out there that understand the need to write "Solid Code" in every go.

The excuse of not having enough time doesn't convince me.... there's a rule from a book I once read that I have applied ever since. The find out the time a project is going to take to be finished, take your first estimate for the design time and double it, take your first estimate for the implementation time and multiply it by 10, take your first time estimate for debugging and testing and triple it; add everything togheter and double it again. The result should be enough to make the project in time! (Barely 🙂 )

There's one problem with that rule. Like with a lot of construction workers would say, "There are two types of workers, the quick and the starv."
 
Originally posted by: thornc
Glad to hear that there people out there that understand the need to write "Solid Code" in every go.

The excuse of not having enough time doesn't convince me.... there's a rule from a book I once read that I have applied ever since. The find out the time a project is going to take to be finished, take your first estimate for the design time and double it, take your first estimate for the implementation time and multiply it by 10, take your first time estimate for debugging and testing and triple it; add everything togheter and double it again. The result should be enough to make the project in time! (Barely 🙂 )

That's a pretty wild way of estimating. I guess it's great if you are an in-house developer where they allow you an absurdly long time to finish the simplest of tasks, but there's no way I'd get any projects if I were that expensive.

Methinks this form of estimation is just to cover up the fact that either a) the developer is poor at estimating his own ability, knowledge and lack thereof, and b) whoever does the requirements is poor at doing so.
 
Originally posted by: BingBongWongFooey
I have the pleasure of working with a few people right now who are *very* good at doing the exact opposite of what that page describes. OOP, specific language strengths, refactoring, descriptive, verbose naming, all go very far to make code alot more elegant and less buggy.

I've seen "verbose naming" get pretty abusive though. Who the hell wants a loop index like IndexForOuterLoopOfPrimaryObjectPropagation

I'm exagerating a bit here ... but I've seen some ugly ones. And if you get to verbose when naming methods it can get really ugly in complicated formulas. Kind of a tradeoff.



 
Originally posted by: ergeorge
Originally posted by: BingBongWongFooey
I have the pleasure of working with a few people right now who are *very* good at doing the exact opposite of what that page describes. OOP, specific language strengths, refactoring, descriptive, verbose naming, all go very far to make code alot more elegant and less buggy.

I've seen "verbose naming" get pretty abusive though. Who the hell wants a loop index like IndexForOuterLoopOfPrimaryObjectPropagation

I'm exagerating a bit here ... but I've seen some ugly ones. And if you get to verbose when naming methods it can get really ugly in complicated formulas. Kind of a tradeoff.

Yeah, for those times when you're gonna have 10 variables on one line, long names definitely are painful, I agree with you. but in general, for class/object/method/function names, HavingAnIntelligableName is better than hvgashrtnm. vnsvnnsvnvsprintf anyone? 😉
 
I agree that having an intelligent name is good, but not everyone has GUI based text editors to work with. Nothing like having to use a shell where you have at most 80 columns and someones variable name or function name takes two lines, which ofcourse has to be wrapped or in somecases it doesn't wrap, making it difficult to read in both cases.

By no means am I saying that you should have variable names that are asdf. But you can also add comments.
Funny thing is, on a same topic, I have found alot of people who want intelligent and super long variable names, don't add units to the variable name if the variable has units. Nothing like propagation time variable without units. Is it sec, ms, microseconds, nano?

Edit: Little mistake
 
I feel that a given name should remain semantically congruous with the type it represents. With that said, verbosity adds little to the semantics if you use a proper name. Consider the following examples:

bool status; // bad name

This is bad because the semantics of "status" implies an infinite number of possible values. status could be true, it could be false; what's that supposed to mean? The semantics imply > 2 states, yet the type limits it to two states.

int status; // still a bad name

Slightly better, but still bad, imo. While the type is now congruous with the poor name choice, it implies an infinit enumber of possible values; hardly ever the case in most systems.

enum status; // good name

Where 'enum' is an appropriate enum defining the possible states of "status." You could then code it like this:

if (status == UserStatus.Active)
// etc.

Completely disambiguated. Some languages don't have enums (Java), so putting the statuses behind a constant would be just fine as well.

static int final USER_STATUS_ACTIVE = 0;

if (status == USER_STATUS_ACTIVE)
// etc.

You lack the type-safety of the enums, but it's still an improvement.

int i; // could be just fine--idiomatic

I usually find these acceptable in the context of a short-scope: loops, iterators, etc.. Outside of that context, it's a horrible name.

for (int i = 0; i < something; i++) // good
foreach (int i in someCollection) // good
int i = 0;
i = 12345234; // bad

string name; // still ambiguous

Not bad, but it could be better. Is this the first name, the full name, the middle name? I would further quality it:

string fullName; // good
string firstName; // good

Again, completely unambiguous.
 
Originally posted by: Ynog
I agree that having an intelligent name is good, but not everyone has GUI based text editors to work with. Nothing like having to use a shell where you have at most 80 columns and someones variable name or function name takes two lines, which ofcourse has to be wrapped or in somecases it doesn't wrap, making it difficult to read in both cases.

By no means am I saying that you should have variable names that are asdf. But you can also add comments.
Funny thing is, on a same topic, I have found alot of people who want intelligent and super long variable names, don't add units to the variable name if the variable has units. Nothing like propagation time variable without units. Is it sec, ms, microseconds, nano?

Edit: Little mistake

I haven't used a gui based text editor in... I don't know how long. I don't consider a text based editor a limitation. I use 110 character or wider terminals all the time, I never really get stuck editing "real" code (vs. some hack shell script) on a text console. That said, most code that's being shared between people gets limited to 80 chars IME.
 
I've had to deal with some crappy code and it ain't my idea of fun. I hate verbose variable names but I also hate cryptic ones as well.
 
Originally posted by: Descartes
Originally posted by: thornc
Glad to hear that there people out there that understand the need to write "Solid Code" in every go.

The excuse of not having enough time doesn't convince me.... there's a rule from a book I once read that I have applied ever since. The find out the time a project is going to take to be finished, take your first estimate for the design time and double it, take your first estimate for the implementation time and multiply it by 10, take your first time estimate for debugging and testing and triple it; add everything togheter and double it again. The result should be enough to make the project in time! (Barely 🙂 )

That's a pretty wild way of estimating. I guess it's great if you are an in-house developer where they allow you an absurdly long time to finish the simplest of tasks, but there's no way I'd get any projects if I were that expensive.

Methinks this form of estimation is just to cover up the fact that either a) the developer is poor at estimating his own ability, knowledge and lack thereof, and b) whoever does the requirements is poor at doing so.

I agree with you, but unfortunately you can't count on other person's abilities....
BTW the formula I gave is wrong is multiply by 3 not 10!! That would give an absourd ammount... even with the 3, this is still a lot of time, but it works!!!!
 
How about this ... I was recently given a library that I ghave to work with. The library is in F95 🙁🙁 They provide a C interface ... every argument for every function is given as a void pointer! For part of it, they actually define function prototypes via typedefs with a typedef for each number of arguments ... heres an example:

typedef long int (NAME_CONVENTION *lib0PtrTypedef)();

typedef long int (NAME_CONVENTION *lib1PtrTypedef)(
void *ptr
);
typedef long int (NAME_CONVENTION *lib2PtrTypedef)(
void *ptr1,
void *ptr2
);
typedef long int (NAME_CONVENTION *lib3PtrTypedef)(
void *ptr1,
void *ptr2,
void *ptr3
);
typedef long int (NAME_CONVENTION *lib4PtrTypedef)(
void *ptr1,
void *ptr2,
void *ptr3,
void *ptr4
);
typedef long int (NAME_CONVENTION *lib5PtrTypedef)(
void *ptr1,
void *ptr2,
void *ptr3,
void *ptr4,
void *ptr5
);
typedef long int (NAME_CONVENTION *lib6PtrTypedef)(
void *ptr1,
void *ptr2,
void *ptr3,
void *ptr4,
void *ptr5,
void *ptr6
);
typedef long int (NAME_CONVENTION *lib7PtrTypedef)(
void *ptr1,
void *ptr2,
void *ptr3,
void *ptr4,
void *ptr5,
void *ptr6,
void *ptr7
);

This goes up to 19 arguments. So you completely through away all type safety for a function call with 19 arguments, many of them are arrays or objects. WTF?? plan on bypassing their C "interface" and calling the FORTRAN directly, if I can get the documentation.
 
That site ain't got nothing on this.

Yes, the linked piece of code actually works, as long as you compile it as straight C, NOT C++.
 
Originally posted by: glugglug
That site ain't got nothing on this.

Yes, the linked piece of code actually works, as long as you compile it as straight C, NOT C++.

I don't find a conscious attempt to obfuscate code as much as possible as nearly as impressive as those who seem to have the inherent ability to do so 🙂
 
Underscores are excellent for creating new identifiers. If you name indices j and k when i is in use, who will know that j and k are indices?....

By using underscores, you can stick with i. If you use i, _i, i_, __i, and i__, most people will lose track. If that fails there is always _i_. Bonus points if the lines below these declarations use the "­¯" symbol (hold down Alt and hit 175 on the keypad).

Better yet, make liberal use of the non-breaking hyphen (­? = alt + 173 on the keypad). Few will catch the subtle difference between x-y and x­?y­­­­­

 
in case anyone cares, all CS students (at least now) should be able to avoid this problem because mose universities teach a clas about data structure/ algorithims. I was fortunate enough to have a CS prof that made sure we thought through our code, and found the best and most efficient way of coding
 
I haven't seen this in a while. Gotta post my reply...

Quote

--------------------------------------------------------------------------------
Originally posted by: thornc
Glad to hear that there people out there that understand the need to write "Solid Code" in every go.

The excuse of not having enough time doesn't convince me.... there's a rule from a book I once read that I have applied ever since. The find out the time a project is going to take to be finished, take your first estimate for the design time and double it, take your first estimate for the implementation time and multiply it by 10, take your first time estimate for debugging and testing and triple it; add everything togheter and double it again. The result should be enough to make the project in time! (Barely )
--------------------------------------------------------------------------------

I agree and I follow that rule, I always double. My old boss knew this and tells the client half of what I said... thus I am under the gun. Is he a dick? most definitly. He also thinks that to optimize webpages made by the company we should cut up .psd files using circles, not rectangles because on circular images u are just wasting size.....
 
Back
Top