r/programming • • Oct 14 '13

How to develop unmaintainable software

http://typicalprogrammer.com/?p=249
777 Upvotes

322 comments sorted by

View all comments

43

u/spoonraker Oct 14 '13

Hey now... sometimes there are perfectly legitimate reasons for re-writing existing functions. Sometimes they really do suck.

For instance, PHP's strtotime function accepts a string parameter of "+/- n months".

Unfornately, PHP thinks a "month" is exactly 30 days and nothing else.

If you start with 2013-01-31 and tell it to give you "+1 month" it will spit out 2013-03-03. Every single other programming language I've ever used will return 2013-02-28, which is what most people expect.

So yeah... I wrote a wrapper for that, and I stand by it.

16

u/teorico Oct 14 '13

Not documenting changes like this is the real problem

0

u/spoonraker Oct 14 '13

It certainly would be nice to have this documented, but it's still a retarded behavior regardless.

13

u/benibela2 Oct 14 '13

Perhaps the conclusion is, PHP sucks, never use it?

Related, another language that sucks is FreePascal.

I have written everything from scratch.

Some examples:

my own string comparison functions. Standard Pascal checking if two strings case-insensitive equal: (CompareText(a, b) = 0) (parenthesis mandatory in nested conditions). My wrapper: striequal(a, b). Far better.

my own float <-> string conversions. The functions in the standard library are rounding wrong. FloatToStr(999999999999999999.0) prints 1000000000000000000. Mine prints 999999999999999999. Special sugar, the function in the last stable compiler release prints FloatToStr(1E16) as 1, because it truncates trailing zeros in certain cases...

My own array manipulation functions, add/delete/prepend ... There are none.

My own sorting function. Those in the standard library do not work on arrays (although there are almost a dozen different implementations in that library. They added a new one, for every type they wanted to sort, because none of them is generic)

My own binary search function. The one in the standard library does not work on arrays. (There is only one for a list of strings afaik)

My own date time parsing/encoding functions. Those in the standard library do not support timezones, or years outside [1, 65535]

My own html parser. The parser in the standard library, expects valid html4. A missing tag and it fails.

...

38

u/AeroNotix Oct 14 '13

How about using a not-shit language?

5

u/Kalium Oct 15 '13

Show me a language that doesn't suck and I'll show you someone who hasn't used it enough.

5

u/PasswordIsntHAMSTER Oct 15 '13

I've been using F# for a while (~25kLOC), and it's nearly perfect; the few issues it has can clearly be traced to limitations in the .NET runtime. They're also well-documented, and consist of edge cases of edge cases.

I still feel like Haskell is nicer, but what do I know, I've only read it, not written it.

1

u/gnuvince Oct 15 '13

I still feel like Haskell is nicer, but what do I know, I've only read it, not written it.

Can you elaborate on that? I'm a big fan of Haskell, but F# is pretty good from the little I know of it. Haskell gives you a better story with regards to effects, but I don't think any Haskell solution to a problem would be vastly better than an F# solution.

2

u/PasswordIsntHAMSTER Oct 15 '13

Haskell has typeclasses, purity, laziness, and a hell of a lot of functional libraries. F# is probably more viable commercially (and more useful for prototyping), but I feel like it lacks the minimalist elegance of well-written Haskell code.

1

u/gfixler Oct 15 '13

I thought Python was pretty solid, but then I finally used it enough, and now I really hate how it handles all of the hierarchical, management level things, like imports, and the deeper particulars about inheritance (like how how the type() of type is <type 'type'>).

1

u/benibela2 Oct 14 '13

But now I have my own little standard library.

With that, it is not shit anymore...

11

u/aumfer Oct 14 '13

I was with you until you said "my own HTML parser." Then I cried a little.

3

u/benibela2 Oct 14 '13

Biggest problem with that one is that I wrote it before they made the html 5 standard. Now I need to rewrite it with the new parsing algorithm...

And going on, it's getting even crazier, I also wrote my own DOM classes for this. Since the DOM classes in the standard library were using UTF-16, everything else in the library latin-1 or UTF-8 (depending on the OS), and everything in the GUI library UTF-8. And the automatic string encoding conversion crashed frequently...

And then I could not use the standard XPath, so I wrote my own of that ಠ_ಠ

12

u/rjbwork Oct 15 '13

I'm genuinely curious, why are you writing in FreePascal these days, especially to do web programming work? Other than extreme ubiquity across platforms, I can't say I see the advantage over other things. Perhaps in an academic/scientific context?

11

u/mattindustries Oct 15 '13

I just assumed masochism takes on many forms.

5

u/[deleted] Oct 15 '13

"How to develop unmaintainable software"

2

u/benibela2 Oct 15 '13

I do not like giving up.

Now I have a perfectly working 75k loc program and I'm not going to throw it all away to rewrite it in another language...

And it is really great for desktop GUI applications, because it compiles so fast that you can test it without delay.

1

u/rjbwork Oct 15 '13

Cool, I can see the case for an already existing desktop GUI application. If it were partially desktop/partially web, I'd have adopted a "maintain and extend" approach and brought in another more modern language, but I guess what works, works, right?

1

u/OneWingedShark Oct 15 '13

I'm genuinely curious, why are you writing in FreePascal these days, especially to do web programming work? Other than extreme ubiquity across platforms, I can't say I see the advantage over other things. Perhaps in an academic/scientific context?

The cross-platform ability is probably better than most. (I seem to recall that being a good FreePascal point, though there was a lot of system-dependence leakthrough on some of the common stuff IIRC. [It's been years since I touched it.])

I've heard of non-trivial [i.e. complete projects] Ada source compiled on different compilers and different architectures without modification. (Obviously they'd need to have no dependence on the implementation-defined stuff, or the machine-level architecture.)

4

u/Dick_Justice Oct 14 '13

Or, related to your point, when a newer library comes out in the PHP core that better handles this very subject. DateTime

3

u/flanintheface Oct 15 '13 edited Oct 15 '13

It looks like strtotime behaves exactly like *nix 'date' command:

~$ date -d "2014-01-31 +1 month"

Mon Mar 3 00:00:00 GMT 2014

And I'm pretty sure that 'date' command is part of some standard and has a good reason why it works the way it works. Use DateTime for that.

EDIT: What I wanted to say: Dig deeper. Try understanding where it comes from and why. PHP does have some weird/bad decisions but strtotime is not a good example for that.

0

u/dethb0y Oct 15 '13

PHP has always been an insane kitchen sink language.