MORE HORROR

jtrammell on 2007-07-05T20:58:40

Also seen today, from the same author:

sub deliver_emails_for_products_and_section_types_for_users_that_have_not_already_received_email {
...
}
(any errant spaces in that sub name were inserted by slashcode...)


Please more code!

educated_foo on 2007-07-06T05:19:00

Unless I'm way off base, the last one was a one-liner (with 80-char lines). Please share more delicious sub body!

Re:Please more code!

jtrammell on 2007-07-06T11:56:52

Nah, I've beat that gong once already this week. But I can tell you it contains:
  1. all lexicals defined at the top
  2. 8 positional sub arguments
  3. indirect object method calls
  4. logic 8 levels deep
  5. no unit tests

could be worse

rjbs on 2007-07-06T09:44:44

It could've been:

sub defpastfuthnare {
  ...
}

long sub names

slanning on 2007-07-06T10:53:46

I don't have a problem with long sub names themselves, though that one looks absurd.
I can imagine using that sub, but it should apparently be broken into two subs, at least,
if it's doing two things (delivering emails, delivering section types).

deliver_emails_for_products would be a wrapper around deliver_emails,
if it's delivering separate emails for several products (maybe I misunderstand it).

deliver_section_types_for_users_that_havent_received_email
would wrap around deliver_section_types:

sub deliver_section_types_for_users_that_havent_received_email {
    my $users = get_users_that_havent_received_email();
    deliver_section_types($users);
}

sub get_users_that_havent_received_email {
    # depends on the problem, might be broken down further
}

I personally like code that is factored out like that,
even with long sub names.
I can see from your previous post, though, that the code inside is probably hideous
in your case.

Re:long sub names

jtrammell on 2007-07-06T12:03:21

Actually, this sub doesn't really deliver any email (the code that does so is not in the lexical scope of that sub). It gathers information about email to send, then calls send_email_to_user_if_not_already_sent().

That sub has fourteen positional arguments.

Re:long sub names

Aristotle on 2007-07-06T13:44:26

“If you have a procedure with 10 parameters, you probably missed some.” —Alan J. Perlis, Epigrams on Programming

Haha

fansipans on 2007-07-06T13:20:20

sub deliver_emails_for_products_and_section_ types_for_users_that_have_not_already_re ceived_email {
...
}

It seems like there's a good joke here; something about how great domain-specific languages are and how "rails with rubies would make this so easy you guys" ... but it's too early in the morning for me .... see, however complex that method is, the method name reads like English! Fantastic!

Re:Haha

jtrammell on 2007-07-06T15:27:41

Somewhere, David A. Huffman is spinning in his grave.