DevDisasters

The Storray Engine

As an independent .NET consultant, Steve was often called in to help smaller development teams transition to the platform. A client asked him to help rebuild some "core technologies" in .NET so the company could offer it as a service to their clients. The first "technology" they wanted to upgrade was something called the Storray Engine.

Simple Arrays
At the requirements meeting, the brain behind the engine gave a quick summary: "It's like having the benefit of a database without ever having to use SQL, ADO or any of that stuff; just simple arrays," he explained. Then they dove into the code. First, they looked at the FindProducts.asp page. The beauty of it, the programmer explained, was that all you needed to do was include a single file, and you had access to all the products and could easily manipulate them with simple array functions:

<!-->include virtual="/Code/Storray
	Engine/Data/PRODS.asp" -->

Steve was curious how this include file might work, so they took a look:

<%
Dim PRODS(487, 7)

... 
PRODS(14,0) = "Black & Decker"
PRODS(14,1) = "Auto Tape Measure"
PRODS(14,2) = "ATM100"
PRODS(14,3) = "/imgs/bd_atm100.gif"
PRODS(14,4) = "<p>Extend and 
	retract with the push of a 
	button</p><ul><li>Blade ... " 
PRODS(14,5) = "21.99"
PRODS(14,6) = "2"
PRODS(14,7) = "True"
...

PRODS(212,0) = "DeWalt"
PRODS(212,1) = "Heavy-Duty XRP 18V 
	Cordless Combo Kit"
PRODS(212,2) = "DC6KTGA"
PRODS(212,3) = "/img/dw_dc6ktg.gif"
PRODS(212,4) = "<p>This 6 pc. tool 
	set comes with our top of the 
	line 18V XRP ..."
PRODS(212,5) = "599.99"
PRODS(212,6) = "84"
PRODS(212,7) = "True"
%>

Hard-Coded "Database"
Steve was aghast -- and a little upset. All of the data -- the names, pricing, categories and everything one would expect in a database -- was hard coded into a VBScript/ASP code file. Steve was trying to keep his cool and figure out a professional exit strategy, but he just had to ask about maintenance. "Maintaining is just as easy," the brain explained. "All you need to know is arrays."

The rest of the Products Maintenance page contained a few array manipulation functions and a call to a save function. "All the real work is in the Core libraries," said the programmer.

Function STORRAYLIB_SaveArray _
		(name, ByRef storray)

	Dim fso, textfile, fileName, i, j

	Set fso = Server.CreateObject(_
		"Scripting.FileSystemObject")

	fileName = Server.MapPath( _
		"/Code/StorrayEngine/Data/" & _
		name & ".asp", True)
	Set file = fso.CreateTextFile(_
		fileName)

	file.WriteLine "<" & "%" & vbCrlf 
	file.WriteLine _
		"Dim STORRAY_" & name & "(" & _
		UBound(storray, 1) & _
		"," & UBound(storray, 2) & _
		")" & vbCrLf

	For i = 0 To UBound(storray, 1)
		For j = 0 To UBound(storray, 2)
			file.Write _
				"STORRAY_" & name & "(" & _
				i & "," & j & ") = " & _
				"""" & Replace(Replace( _
				storray(i,j),"""",""""""),_
				vbCrLf,"") & """" & vbCrLf
		Next
	Next

As Steve gawked at the wonder that was the Storray Engine, the programmer commented, "Yeah, I just can't figure out how to bring this into .NET. I'm thinking of using classes instead, but man, it's hard to compile stuff at run time!"

About the Author

Alex Papadimoulis lives in Berea, Ohio. The principal member of Inedo, LLC, he uses his 10 years of IT experience to bring custom software solutions to small- and mid-sized businesses and to help other software development organizations utilize best practices in their products. On the Internet, Alex can usually be found answering questions in various newsgroups and posting some rather interesting real-life examples of how not to program on his Web site TheDailyWTF.com. You can contact Alex directly via email at [email protected].,

comments powered by Disqus

Featured

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events