Live data from Hacker News

Let's Write Some Bad Ruby

hashrocket.com

11–20 of 37 posts

Re: Let's Write Some Bad Ruby

#12
post #2

I have a scratch folder full of stuff like this written in whatever scripting language is closest at hand, ruby, perl, python, etc. I'd wager most people here would have something similar. I wonder if it would be an interesting project to comb though it all and see if any useful tools could be extracted. Probably not, like the code in this blog most of my one-offs are unashamedly terrible.

I didn't really think it was that terrible or hard to understand. I have minimal experience with Ruby and it made sense to me. Doing this sort of thing was why I learned how to program in the first place.

Re: Let's Write Some Bad Ruby

#13
Another awesome tool if you're using emacs is wgrep mode. You get the results of `grep` in a buffer, can edit it like any other text in emacs, and then save writes back to all the original files. Really cool.

Emacs macros are wonderful too.

Re: Let's Write Some Bad Ruby

#14

Whilst not entirely the point of the article, this could have been accomplished without moving any files by changing the route definition to a scope from a namespace in Rails...

lol I know right, just enough knowledge to be dangerous...

that may come off as mean/rude towards the author, but I don't mean it so. I do shit like this all the time because I don't know every little trick with the languages/frameworks I'm using, it's impossible to know it all unfortunately.

Re: Let's Write Some Bad Ruby

#15
post #12
post #2

I have a scratch folder full of stuff like this written in whatever scripting language is closest at hand, ruby, perl, python, etc. I'd wager most people here would have something similar. I wonder if it would be an interesting project to comb though it all and see if any useful tools could be extracted. Probably not, like the code in this blog most of my one-offs are unashamedly terrible.

I didn't really think it was that terrible or hard to understand. I have minimal experience with Ruby and it made sense to me. Doing this sort of thing was why I learned how to program in the first place.

Couldn't agree more. If you write something for one time use and it works how could it really be bad?

Re: Let's Write Some Bad Ruby

#16

Whilst not entirely the point of the article, this could have been accomplished without moving any files by changing the route definition to a scope from a namespace in Rails...

lol I know right, just enough knowledge to be dangerous... that may come off as mean/rude towards the author, but I don't mean it so. I do shit like this all the time because I don't know every little trick with the languages/frameworks I'm using, it's impossible to know it all unfortunately.

I think the key point is that it is 'impossible to know it all'

I don't think I have ever looked at code I have written more than a few months ago and NOT found a bunch of things I could have done much simpler if I had just known about some feature or trick. I have stopped feeling bad when that happens; now, I figure that the day I stop experiencing that is the day I am no longer getting better as a programmer.

Re: Let's Write Some Bad Ruby

#17

Whilst not entirely the point of the article, this could have been accomplished without moving any files by changing the route definition to a scope from a namespace in Rails...

I had the same thoughts. Why would a company like HashRocket use such an example? Or did they just not know? I don't know.

Re: Let's Write Some Bad Ruby

#18
post #2

I have a scratch folder full of stuff like this written in whatever scripting language is closest at hand, ruby, perl, python, etc. I'd wager most people here would have something similar. I wonder if it would be an interesting project to comb though it all and see if any useful tools could be extracted. Probably not, like the code in this blog most of my one-offs are unashamedly terrible.

I wholeheartedly recommend anyone to comb through their samples and post them on github - https://github.com/voltagex/junkcode is mine. Occasionally I'll graduate projects to their own repo.

This was inspired by http://samba.org/ftp/tridge/talks/junkcode.pdf - you may recognise the author!

Re: Let's Write Some Bad Ruby

#19
post #4

This is the sort of thing a combination of bash/grep/awk/sed is good for also.

True, but if you write Ruby all day and are most familiar with it, a script like this takes a matter of minutes to write compared to trawling the man pages of grep/awk/sed to implement the same thing you're only going to throw away after execution anyway.

After you are familiar with the shell tools, it takes seconds to write something like this, not minutes.

Re: Let's Write Some Bad Ruby

#20
post #2

I have a scratch folder full of stuff like this written in whatever scripting language is closest at hand, ruby, perl, python, etc. I'd wager most people here would have something similar. I wonder if it would be an interesting project to comb though it all and see if any useful tools could be extracted. Probably not, like the code in this blog most of my one-offs are unashamedly terrible.

> most of my one-offs are unashamedly terrible.

I never intended this to see the light of day, but since the topic warrants it, here is a python one-liner I'm using to put the indices of combinations of subsets into one list:

combos = map(list,reduce(lambda x,y: x+y,[[c for c in itertools.combinations(range(8),i)] for i in range(1,9)]))

yuck. These things usually end up as a result of testing and tweaking in an interactive shell.

Post reply on HN