Live data from Hacker News

Hopefully more controversial programming opinions

prog21.dadgum.com

61–70 of 103 posts

Re: Hopefully more controversial programming opinions

#61
post #29

Earlier quoted context omitted.

This reminds me of a manager of mine who wrote a 10,000 line Perl script. He thought himself how to write Perl in a week. And then started coding. He wrote a script to automate a very tedious testing process so perfectly, we were able to reduce our test team by like 70% and test more precisely than before. It was fully procedural code. And it looked monstrous. Our architect challenged him that it won't workout. He ev…

Isn't your list a variation on the well known list of: - Make it work - Make it right - Make it fast http://c2.com/cgi/wiki?MakeItWorkMakeItRightMakeItFast

Depends on whether step 2 is a complete rewrite (in a different language) or further hacking to "make it right".

My process tends to be:

1. Make it work - Knock up a prototype (lots of assumptions made and noted, limited error checking, etc)

2. Make it right - By starting from scratch and use what was learned in making the prototype

3. Make it fast(er) - Having a prototype, and trying it at scale, should have already given me an idea of what algorithms/structures to use/avoid in Stage #2 but, obviously, a further optimisation stage will almost always be beneficial.

Ideally (if time allows) the prototype is written in a completely different language to the desired target. This is the most important point.

Most of the production code I write is C and I tend to do my prototypes in Perl. The helps me for several reasons:

a) ADTs (lists, hashes/dictionaries, etc) are just easier/quicker in Perl/python/ruby than in C (I do have my own C library that I reuse for ADTs so it's not as if it's a great chore writing them each time, but ADT instantiation is just easier in Perl/python/ruby than C).

b) It's also easier to play around with different algorithms if you can switch between ADTs more easily.

c) I can use the prototype stage to continue to learn new languages (it used to just be Perl but has extended to include languages like Python and ruby). This list will keep on growing.

d) It prevents me (or the business) stopping at Stage #1 and using the prototype code for production. (This could be even worse if the prototype was written in C.)

e) A prototype, being quicker to knock up, means faster to getting it in-front of someone else to look at and give feedback.

f) It prevents me just copy-and-pasting chunks of the prototype code as production code so I, hopefully, don't carry over any of the assumptions I'd made in creating the prototype.

g) "Knock up a prototype" doesn't mean no design/testing/etc. I usually end up with design notes and some automated black box testing that can be reused in the later stages.

Re: Hopefully more controversial programming opinions

#62
post #54
post #40

Earlier quoted context omitted.

To make something fast or to make something scale you don't need a proof. You need a profiler.

A profiler is for micro optimisations. A profiler won't let you go from bubble to quick sort for example.

In my view, all performance optimisations need to be driven by hard data and a profiler is just one source of this kind of data.

Re: Hopefully more controversial programming opinions

#63
post #54
post #40

Earlier quoted context omitted.

To make something fast or to make something scale you don't need a proof. You need a profiler.

A profiler is for micro optimisations. A profiler won't let you go from bubble to quick sort for example.

A profiler will tell you if sorting actually using a meaningful amount time in your application.

If you go ahead and blindly change your bubble sorts for quick sorts then at best you may be wasting time doing something that has no effect on performance, and at worst you may be making your program slower.

Quicksort is slower than bubble sort for nearly sorted input after all.

Re: Hopefully more controversial programming opinions

#64
post #48

> Purely functional programming doesn't work, but if you mix in a small amount of imperative code then it does. That isn't controversial nor is it an opinion. It's just the truth. Purely functional code has no side effects. The entire point of a program is to have side effects.

Not true. For example, a compiler can be a pure function. It accepts input that is the source code, and outputs the machine code. There's no side effect there. I admit it needs minor scaffolding to always read all of stdin first, and write all to stdout at the end, but the programme, as written by the programmer, is a pure function. This is one of several ways that Haskell worked before there was an IO monad [1], all…

This is even the case after the introduction of the IO monad. Monads allow referentially transparent IO.

My purely functional programs actually do things! Amazing that my ivory tower allows me to say "Hello World".

Re: Hopefully more controversial programming opinions

#65
post #39

Earlier quoted context omitted.

I'm actually currently in process of writing a small library, but I have only 6 years of experience. I'm frightened.

Don't be. That idea is bollocks. Experience has approximately zero correlation with ability. (how's that for controversial?)

So true. I've seen people who have way more than the fabled "10,000 hours" of software development experience them that continue to push out truly woeful code.

Re: Hopefully more controversial programming opinions

#66
post #54

Earlier quoted context omitted.

A profiler is for micro optimisations. A profiler won't let you go from bubble to quick sort for example.

A profiler will tell you if sorting actually using a meaningful amount time in your application. If you go ahead and blindly change your bubble sorts for quick sorts then at best you may be wasting time doing something that has no effect on performance, and at worst you may be making your program slower. Quicksort is slower than bubble sort for nearly sorted input after all.

It does give you information on where the most time is being spent, but it doesn't tell you what to implement. Without adequate algorithm knowledge you might try a micro optimisation when it really needs a completely different algorithm.

With superficial knowledge you might stick to certain rules without really understanding them. That bubble sort example you gave is a perfect example.

Re: Hopefully more controversial programming opinions

#67
post #43

Earlier quoted context omitted.

The architect sounds obsessed with Java... first sign of craziness! Disclaimer: I like C/C++/Python.

Actually its all the 'design' craze. Most architects think drawing UML diagrams on mspaint to be a sign of technical superiority. The real issue I think is heavy OO programmers(read java) can't live without. 1. Design patterns- The art of bloating already heavily bloated code. 2. Avoiding meta programming of any kind. 3. Love towards getters/settters and absolutely anything that lends to code bureaucracy. Why get/set…

Ugh... don't blame "design patterns". They are just tools, and any good developer utilizes them nearly constantly. Are we really going to suggest that you can write good imperative code that doesn't involve delegation, strategies, or factories at some level?

The issue is with a culture that thrives on complicating relatively simple concepts by abusing those tools, not with the tools themselves.

Design patterns don't make for bad code, bad coders do.

Re: Hopefully more controversial programming opinions

#68
post #9

Here's my version of his opinions, probably even more controversial :P. CS should be offered as a major by itself. All the most interesting stuff is CS-specific with indirect applications. Working on something like automatic programming is far more exciting than working on biology or art or what have you. (I can't think of anything more awesome or more CS-only than automatic programming.) It is a mistake to introduce…

Pretty code is readable and readable code is pretty. If you can render your code as a nice pdf and distribute it as a paper, it's about as readable as it will ever be. Even if you can't, remember that aesthetics aren't random--there is a reason why pretty code is pretty.

I'll restate this: "Every programmer should know more than a little bit about typography". I was amazed at how much learning design fundamentals improved me as a programmer. I've learned to communicate through code much more effectively than I ever had before. Thinking about grouping, spacing, and the like leads not only to more readable ("pretty") code but usually more efficient code as well.

Re: Hopefully more controversial programming opinions

#69
post #54
post #40

Earlier quoted context omitted.

To make something fast or to make something scale you don't need a proof. You need a profiler.

A profiler is for micro optimisations. A profiler won't let you go from bubble to quick sort for example.

Maybe not, but Google will:)

Re: Hopefully more controversial programming opinions

#70
post #59

Earlier quoted context omitted.

oh hell yeah, absolutely. This sort of code is not uncommon at all but is pretty much incomprehensible (let alone maintainable) for anyone beyond the original implementer

If one day somebody else does inherit the codebase, are there any tools out there that are designed to help people in that situation? Like something that de-spaghettifies everything?

Appropriately, it's a book: http://www.amazon.com/Working-Effectively-Legacy-Michael-Fea...

Some automatic tools could help (although I doubt thay'll work on DBase III): Static analysis to see what's there, version control to start at the top and log your way through and be able to rollback to a previous working version.

But it's at the very least weeks of pain.

Post reply on HN