News for hackers. Stuff that matters.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by gaius on Thursday June 04, 2009 @03:16PM (#641999)
Your point 2 is far from ridiculous. We do it that way so the business logic exists and is enforced in one place rather than being scattered around this desktop app and that website and so on. Only the most trivial applications can afford to put all their business logic in the middle tier.

Also I'm not allowed to use OCaml in production systems because too few people at the company speak it. Annoying for me, but again far from ridiculous.

Re:Ask HN: Ridiculous Coding Practices by companies you have... by stcredzero on Thursday June 04, 2009 @04:33PM (#642154)
Point 2 is a bad idea. SQL stored procedures are not a good way to implement business logic. Of course, people who hold the opinion that OO is a bad idea would think it's a great way -- it's pretty much the opposite of OO.

We do it that way so the business logic exists and is enforced in one place...Only the most trivial applications can afford to put all their business logic in the middle tier.

There are much better ways of enforcing business logic and controlling it all in one place, which would be compatible with configuration management/source control and much more convenient for most programming teams.

(Namely: just publish the business logic as a library and have standards that dictate its use. These can be enforced using automated scripts and a little process. You are also not restricted to the middle tier, though I'd still say it's a good idea.)

Re:Ask HN: Ridiculous Coding Practices by companies you have... by gaius on Friday June 05, 2009 @03:30AM (#642857)
just publish the business logic as a library and have standards that dictate its use

LOL!! Why not put the business processes in the standards too, then you won't need any code!

The point is, no-one running any apps against your database has a choice but to respect the business processes if it's all implemented in stored procs. You are protected from malice, from incompetence, from simple human error, and your auditors and regulators and shareholders are happy. Maybe no-one cares if it's only a website.

Also I am hilariously amused that you don't think stored procedures can live in version control like any other source code.

Re:Ask HN: Ridiculous Coding Practices by companies you have... by asb on Thursday June 04, 2009 @06:39PM (#642381)
Stored procedures don't seem like a bad approach to me. You can provide versioning support by doing something much like Rails migrations. Providing access to the database through stored procedures basically is publishing business logic as a library. I'll admit pl/pgsql looks a little funky, but it doesn't seem too bad.

I'll note I'm not talking from experience here, I'm just speculating and hoping for somebody with more practical experience in the matter (or better insight) to enlighten me.

Re:Ask HN: Ridiculous Coding Practices by companies you have... by stcredzero on Thursday June 04, 2009 @06:50PM (#642396)
If it is "basically...publishing business logic as a library" then why incur the expense of using such a scheme? Just publish the darn library and put it on a read-only shared directory. Why give up the use of purpose built version control and programming tools? Why give up the modularity and increased productivity that a high level language can give you?

Most of the time, it's because the organization thinks in terms of SQL and relational tables. There are better ways to do business logic.

Re:Ask HN: Ridiculous Coding Practices by companies you have... by arghnoname on Friday June 05, 2009 @10:02AM (#643189)
As a language, it's pretty painful to use and you run into those limitations pretty quickly. You also put more processing in the database, which isn't great for scalability. It is nice being able to test changes via the sql prompt though. A library + console app might be a good compromise.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by jrockway on Thursday June 04, 2009 @05:25PM (#642267)
Your point 2 is far from ridiculous. We do it that way so the business logic exists and is enforced in one place rather than being scattered around this desktop app and that website and so on. Only the most trivial applications can afford to put all their business logic in the middle tier.

But of course, the middle layer that applications talk to need not be the database. A simple RPC server between the apps and the database makes maintaining the system significantly easier. Your procedures are "normal code" that you already have a toolchain in place for dealing with. (Testing, libraries, version control, etc.)

The environment is richer, which means the middle tier can handle caching, sharding, replication, auditing, and anything else that you might need to add. And, you can add these things incrementally, without touching the apps that speak to this server.

IMHO, stored procedures are a quick hack that are barely viable for even the simplest tasks. Many people seem to disagree, but I doubt they have ever considered any other way.

(A notable example of this system is Flickr. Their internal apps, like the public web interface, use the Flickr API to do their work. In this case, the web app that powers the API is the "middle layer"/"RPC server". I think this worked out pretty well for them, and it made it easy to expose their database to third parties.)

Re:Ask HN: Ridiculous Coding Practices by companies you have... by ohhmaagawd on Thursday June 04, 2009 @04:25PM (#642145)
this was common practice about 15 years ago, before people discovered that putting biz logic in stored procs really sucked for UI interaction, sucked for maintainability (stored proc languages really suck), and truly sucked for scalability.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by sports_guy on Thursday June 04, 2009 @05:11PM (#642244)
It sucks yes, but working at a place where there are a groups of people that commonly access the database to do operations that cannot be done from the front end you definitely want procedures. They use different tools for a variety of tasks and when the business logic isn't in procedures its very easy for them to break things and they have and do.... Our DBA however wants all procedures for all access which I find to also be an extreme example for the reasons you mention as not all data needs this level of control as its just simple CRUD operations and tables they should never change anyways.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by brown9-2 on Thursday June 04, 2009 @10:20PM (#642586)
Well then in this case you have a people problem, not a software problem.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by pmichaud on Thursday June 04, 2009 @04:41PM (#642165)
The alternatives are not

1) Sproc 2) Scattered around the app haphazardly

The only apps I've seen use the BLL-as-an-sproc trick were written by people without any experience writing scalable code at a real company.

Re:Ask HN: Ridiculous Coding Practices by companies you have... by gaius on Friday June 05, 2009 @01:47AM (#642755)
Really? Most of my experience is on trading systems handling thousands of real-money transactions per second, and stored procedures are the only proven approach.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by cromulent on Friday June 05, 2009 @12:39AM (#642689)
SAP has all it's business logic in the middle tier, and I wouldn't call it trivial.
Re:Ask HN: Ridiculous Coding Practices by companies you have... by viggity on Thursday June 04, 2009 @05:35PM (#642292)
My dad can beat up your dad.