Ashwin Purohit

Essays & Articles

Turducken Code

I recently came across this line of Python code:

shipping = TextField(u’First Name’, label=’<a href=“[email protected]”
onClick=“helpDialog();”>Help</a>’, validators=…)

Smell that? There’s an onClick handler in an <a/> tag in a Python string. Javascript in HTML stuffed into Python. The abominable “Turducken Code.”

Turducken

You can stomach mixing two programming languages, but three is gross. In HTML, it’s common to inline CSS or JS here and there, trading convenience for the ability to cache stylesheets and script files, and to keep logic separate. Pretend you have a turkey. Whenever you inline code, visualize yourself hand-shoving another baked animal into that turkey. Grotesque.

Did you add JavaScript to index.html instead of in a cacheable .js file? Did you inline some CSS for a button, instead of abstracting it into a cacheable style.css?

You defined a string Template = “<html>…“; in your backend code, and in it, inlined your JavaScript and CSS? That’s stuffing a chicken inside a duck, and then stuffing the whole thing in a turkey. You just wrote Turducken code, and I’m not coming to your Thanksgiving dinner.

[email protected]

Berlin-based software engineer building machine learning backends.

If you're in the area, send me an email! I'd love to get coffee.

Want updates when I write?