CodeSOD: Unnavigable
Do you know what I had forgotten until this morning? That VBScript (and thus, older versions of Visual Basic) don't require you to use parentheses when calling a function. Foo 5 and Foo(5) are the same thing. Of course, why would I remember that? I thankfully haven't touched any of those languages since about… 2012. Which is actually a horrifyingly short time ago, back when I supported classic ASP web apps. Even when I did, I always used parentheses because I wanted my code to be something close to readable. Classic ASP, there's a WTF for you. All the joy of the way PHP mixes markup and code into a single document, but with an arguably worse and weirder language. Which finally, brings us to Josh's code. Josh worked for a traveling exhibition company, and that company had an entirely homebrewed CMS written in classic ASP. Here's a few hundred lines out of their navigation menu.

Do you know what I had forgotten until this morning? That VBScript (and thus, older versions of Visual Basic) don't require you to use parentheses when calling a function. Foo 5
and Foo(5)
are the same thing.
Of course, why would I remember that? I thankfully haven't touched any of those languages since about… 2012. Which is actually a horrifyingly short time ago, back when I supported classic ASP web apps. Even when I did, I always used parentheses because I wanted my code to be something close to readable.
Classic ASP, there's a WTF for you. All the joy of the way PHP mixes markup and code into a single document, but with an arguably worse and weirder language.
Which finally, brings us to Josh's code. Josh worked for a traveling exhibition company, and that company had an entirely homebrewed CMS written in classic ASP. Here's a few hundred lines out of their navigation menu.
class=menuMain>
<% if menu = "1" then
Response.Write "- Home
"
else
Response.Write "- Home
"
end if
if menu = "2" then
Response.Write "- About us
"
else
Response.Write "- About us
"
end if
if menu = "3" then
Response.Write "- How to book
"
else
Response.Write "- How to book
"
end if
if menu = "4" then
Response.Write "- Expeditions
"
else
Response.Write "- Expeditions
"
end if
if menu = "5" then
Response.Write "- Safety
"
else
Response.Write "- Safety
"
end if
if menu = "6" then
Response.Write "- Fundraising
"
else
Response.Write "- Fundraising
"
end if
if menu = "7" then
Response.Write "- Work for us
"
else
Response.Write "- Work for us
"
end if
if menu = "8" then
Response.Write "- Contact us
"
else
Response.Write "- Contact us
"
end if
Response.Write "
"
Response.Write "
if menu = "1" then
end if
if menu = "2" then
if submenu = "1" then
Response.Write "Who we are "
else
Response.Write "Who we are "
end if
if submenu = "2" then
Response.Write "CSR "
else
Response.Write "CSR "
end if
if submenu = "3" then
Response.Write "Partners and accreditation "
else
Response.Write "Partners and accreditation "
end if
if submenu = "4" then
Response.Write "Curriculum links "
else
Response.Write "Curriculum links "
end if
if submenu = "5" then
Response.Write "Expedition advice "
else
Response.Write "Expedition advice "
end if
if submenu = "6" then
Response.Write "Press resources "
else
Response.Write "Press resources "
end if
end if
if menu = "3" then
Response.Write ""
end if
if menu = "4" then
if submenu = "1" then
Response.Write "Central and North America "
else
Response.Write "Central and North America "
end if
if submenu = "2" then
Response.Write "South America "
else
Response.Write "South America "
end if
if submenu = "3" then
Response.Write "South East Asia "
else
Response.Write "South East Asia "
end if
if submenu = "4" then
Response.Write "Asia "
else
Response.Write "Asia "
end if
if submenu = "5" then
Response.Write "Africa "
else
Response.Write "Africa "
end if
if submenu = "6" then
Response.Write "Europe "
else
Response.Write "Europe "
end if
if submenu = "7" then
Response.Write "Community projects "
else
Response.Write "Community projects "
end if
if submenu = "8" then
Response.Write "Independent "
else
Response.Write "Independent "
end if
end if
if menu = "5" then
if submenu = "1" then
Response.Write "Safe people "
else
Response.Write "Safe people "
end if
if submenu = "2" then
Response.Write "Safe places "
else
Response.Write "Safe places "
end if
if submenu = "3" then
Response.Write "Safe practices and policies "
else
Response.Write "Safe practices and policies "
end if
if submenu = "4" then
Response.Write "Safe resources "
else
Response.Write "Safe resources "
end if
if submenu = "5" then
Response.Write "Operations Centre "
else
Response.Write "Operations Centre "
end if
if submenu = "6" then
Response.Write "Travelsafe course "
else
Response.Write "Travelsafe course "
end if
end if
if menu = "6" then
' if submenu = "1" then
' Response.Write "Fundraising team "
' else
' Response.Write "Fundraising team "
' end if
if submenu = "2" then
Response.Write "Fundraising ideas "
else
Response.Write "Fundraising ideas "
end if
if submenu = "3" then
Response.Write "Fundraising events "
else
Response.Write "Fundraising events "
end if
end if
if menu = "7" then
if submenu = "1" then
Response.Write "Lead an expedition "
else
Response.Write "Lead an expedition "
end if
if submenu = "2" then
Response.Write "Office based positions "
else
Response.Write "Office based positions "
end if
end if
if menu = "8" then
if submenu = "1" then
Response.Write "Request a brochure "
else
Response.Write "Request a brochure "
end if
if submenu = "2" then
Response.Write "Sign up for e-news "
else
Response.Write "Sign up for e-news "
end if
if submenu = "3" then
Response.Write "Press resources "
else
Response.Write "Press resources "
end if
end if %>
This renders the whole menu, but based on the selected menu and submenu, it adds an activ
class to the HTML elements. Which means that each HTML element is defined here twice, once with and without the CSS class on it. I know folks like to talk about dry code, but this code is SOGGY with repetition. Just absolutely dripping wet with the same thing multiple times. Moist.

What's Your Reaction?






