May 18th, 2014

I thought it would be funny to go through source code and replace all the keywords with synonyms (eg. try –> attempt, catch –> seize). The results didn’t end up being that funny. But when I tried replacing all the words in various pieces of code with auto-generated synonyms the results were fairly magical.

Python

#!/usr/bin/env pythonimportosimportrequestsimportjsonimportarrow,datetime,timefromtzlocalimportget_localzonefromconfigimportapikey,startsecond,startminute,starthour,startday,startmonth,startyear,endsecond,endminute,endhour,endday,endmonth,endyear,minlat,maxlat,minlon,maxlondefmake_call(s,f,data):params={'api_key':apikey,'start_time':s,'end_time':f,'min_lat':minlat,'max_lat':maxlat,'min_lon':minlon,'max_lon':maxlon}r=requests.get('https://pressurenet.io/live',params=params)print"Request made to "+r.urlprintarrow.get(str(s/1000)).format('MMMM-DD-YYYY:HH:mm:ss')+" to "+arrow.get(str(f/1000)).format('MMMM-DD-YYYY:HH:mm:ss')print"Status: {}".format(r.status_code)ifr.status_code==200:print"{} items downloaded".format(len(r.json()))iflen(r.json())>0:data+=r.json()stime=arrow.get(datetime.datetime(startyear,startmonth,startday,starthour,startminute,startsecond,tzinfo=get_localzone()))origstart=stimeftime=arrow.get(datetime.datetime(endyear,endmonth,endday,endhour,endminute,endsecond,tzinfo=get_localzone()))data=[]ftimestamp=ftime.timestamp*1000#don't ask for more than 1 day's data at a timewhile(ftime-stime).days>1:stimestamp=stime.timestamp*1000ftimestamp=stime.replace(days=+1).timestamp*1000make_call(stimestamp,ftimestamp,data)stime=arrow.get(ftimestamp/1000).replace(seconds=+1)time.sleep(10)stimestamp=stime.timestamp*1000ftimestamp=ftime.timestamp*1000make_call(stimestamp,ftimestamp,data)fn=os.path.join('data','{startdate}_{enddate}_{minlat}-{maxlat}_{minlon}-{maxlon}.json'.format(startdate=origstart.format('MMMM-DD-YYYY:HH:mm:ss'),enddate=ftime.format('MMMM-DD-YYYY:HH:mm:ss'),minlat=minlat,maxlat=maxlat,minlon=minlon,maxlon=maxlon))print"Data saved to "+fnwithopen(fn,'w+')asoutfile:json.dump(data,outfile)outfile.close()

Paraphrased Code

The first two lines of this reworded script are a highlight for me: “import os” and “import requests” becomes “spell osmium” and “spell bespeak”. My expectations are already exceeded. I’m also fond of how the variable “f” becomes “degree Fahrenheit” and “sleep” becomes “kip”! Delightful. Lastly I have to point out the third last line: “with unfastened(fn, ‘w+’) arsenic outfile:”. Sounds dangerous – let’s do it!

#!/usr/bin/env pythonspellosmiumspellbespeakspelljsonspellpointer,datetime,clockfromtzlocalspellget_localzonefromconfigspellapikey,startsecond,startminute,starthour,startday,startmonth,startyear,endsecond,endminute,endhour,endday,endmonth,endyear,minlat,maxlat,minlon,maxlondefmake_call(second,degreeFahrenheit,information):params={'api_key':apikey,'start_time':second,'end_time':degreeFahrenheit,'min_lat':minlat,'max_lat':maxlat,'min_lon':minlon,'max_lon':maxlon}roentgen=bespeak.get('https://pressurenet.io/live',params=params)publish"Request made to "+roentgen.URLpublishpointer.get(str(second/1000)).arrange('MMMM-DD-YYYY:HH:mm:ss')+" to "+pointer.get(str(degreeFahrenheit/1000)).arrange('MMMM-DD-YYYY:HH:mm:ss')publish"Status: {}".arrange(roentgen.status_code)ifroentgen.status_code==200:publish"{} items downloaded".arrange(len(roentgen.json()))iflen(roentgen.json())>0:information+=roentgen.json()stime=pointer.get(datetime.datetime(startyear,startmonth,startday,starthour,startminute,startsecond,tzinfo=get_localzone()))origstart=stimeftime=pointer.get(datetime.datetime(endyear,endmonth,endday,endhour,endminute,endsecond,tzinfo=get_localzone()))information=[]ftimestamp=ftime.timestamp*1000#don't ask for more than 1 day'second information at a clockpiece(ftime-stime).years>1:stimestamp=stime.timestamp*1000ftimestamp=stime.supplant(years=+1).timestamp*1000make_call(stimestamp,ftimestamp,information)stime=pointer.get(ftimestamp/1000).supplant(2nd=+1)clock.kip(10)stimestamp=stime.timestamp*1000ftimestamp=ftime.timestamp*1000make_call(stimestamp,ftimestamp,information)fn=osmium.way.fallin('information','{startdate}_{enddate}_{minlat}-{maxlat}_{minlon}-{maxlon}.json'.arrange(startdate=origstart.arrange('MMMM-DD-YYYY:HH:mm:ss'),enddate=ftime.arrange('MMMM-DD-YYYY:HH:mm:ss'),minlat=minlat,maxlat=maxlat,minlon=minlon,maxlon=maxlon))publish"Data saved to "+fnwithunfastened(fn,'w+')arsenicoutfile:json.ditch(information,outfile)outfile.near()

Paraphrased Code

At first I was too distracted by how the comment at the top of this file sounds like it’s been through Google translate too many times to notice that it renamed me “Natalie bleak”! That’s definitely what I’ll go by should I ever join a doom metal band.

This rewording – with its “work”, “turn over”, “supply”, “volt-ampere”, “joule”, and “mathematics.shock” (my personal favourite) – sounds like it was composed by a soulless capitalist robot. A big, lumbering capitalist robot with a soft spot for tacos, as indicated by line 35 (to be fair, “tacos” was left over from a debugging line in the original script).