Winter Break and Advent of Code

This winter break I gave myself the project of becoming more proficient in standard Ruby (sans Rails). In order to do this I did a bunch of coding challenges. One of the sets of challenges I tried was an Advent calendar made up of coding puzzles.

I wanted to write up a blog post about what what I learned about Ruby from gaining all 50 advent of code stars. I did a great job of erasing all Rails from my mind this break and concentrating on my programming fundamentals and use of Ruby. This will probably hurt a lot when I return to class on Monday but it also helped to cement things I’ve learned so far and teach me new things about programming. So here are a couple of things I learned from this winter adventure.

Screen Shot 2016-01-02 at 6.14.17 PM.png

Advent of Code is a 25 day challenge leading up to December 25. It’s a fun project put together so that it’s accessible for all skill levels and can be completed in any programming language. I am definitely bookmarking AoC for when I have to learn a new programming language. I tried the first five days in R and Ruby and it helped me relearn a lot of the R I’ve slowly been pushing out of my brain. My GitHub repo of AoC can be found here. This is not the prettiest code in the world and there are definitely exercises I’m more proud of than others, but regardless of code quality it’s something I finished and I learned a lot in the process. Here are a few of the things I learned.

1. Range of CS-Related Topics

What I really liked about the layout of the challenges is that most touched on a range of topics in the development world. One challenge took advantage of parsing JSON files, something web devs would know a lot about. One talked about MD5 hashes, and another about password encryption, which relates to cybersecurity. There was a challenge that related to hardware, one for bitwise operators, and lots of interesting sorting problems. It was a fantastic array of subjects to learn about for someone who has only been programming for a little while. I learned a lot about Regular Expressions as many of the puzzles had to do with large amounts of string input. I also was able to brush up on my math for the puzzles that involved coordinates. Overall, once you have the basics of a language down, doing coding puzzles like this can really help introduce you to CS topics when you did not go to school for that. The one area where my background in economics helped me was on an optimality constraint problem where you calculate happiness of guests based on who they are sitting next to. But besides that, I was pretty lost when solving problems with “jumps” and “registers” and learned a lot in the process.

2. Every Language Has Strengths and Weaknesses

During my three weeks of working on Advent of Code, I spent a lot of time on the AoC sub-Reddit reading about how people saw the problem and looking at code in Python, Java, C#, C++, Ruby, and many many more languages. I had the most fun with people’s solutions that didn’t even use code at all, but instead used pen and paper and manual logic to solve the problem. In this process, I started to realize how lucky I was to have Ruby for some of the more Object Oriented problems (everything in Ruby is an object, EVERYTHING!) and how sad I felt on the Math problems or things like bitwise operators where other languages naturally excel. By about the 10th day I could really tell if a problem could be easily solved in Ruby right away and just see the algorithm in my head if that were the case.

3. Classes, Hashes, Arrays, oh my!

I learned a lot about the various advantages and disadvantages of data structures doing these puzzles. I generally am inclined towards using arrays and hashes, but there were many times I had to scrap my algorithm half-way through realizing that I should create my own class instead. Classes are great ways to organize related data and reuse that information later. My first reaction as a new programmer is always to go for a simple way of storing the data like an array. Working through more complex puzzles made me teach myself to use objects much more often. Instances could sometimes hold information so much more clearly than hashes could. This was the most helpful on the horrible two days at the end of the puzzles where you had to basically build an RPG in order to calculate minimums. I also quickly began to adapt using hashes much more often than arrays. The information in a hash can be unordered and pulled out without an index, but with a reasonable call like a name or identifier, which is super helpful when you have a lot of information and don’t want to remember the order. I kicked myself many times for using arrays early on and then having no idea where my data was by the end of the code. I also internalized a lot about classes and object creation in the longer puzzles.

4. Countless Amazing Ruby Things

The biggest thing I learned during the last two weeks has been all of the amazing Ruby modules, methods, gems, etc. that make doing hard stuff easy. The three biggest modules I learned advanced things about while solving the puzzles were Array, Enumerable, and Regexp. I probably know or have seen every Ruby enumerable at this point. Here are my new favorite Ruby things in no particular order:

  1. #each_cons(n): gives you arrays of n amount in consecutive order so if you called it on [1, 2, 3, 4] and wanted arrays of 2 it would give you back [1, 2], [2, 3], [3, 4]. Isn’t that grand? Great for combinations of linear items.
  2. #combination(n) and #permutation(n): Give an array and the number of elements in each array and get all combinations or permutations of that array. The difference between these two methods was hard to get used to. Basically, if order matters you want a combination and if it doesn’t, go for permutation.
  3. Class: Set:  I used sets a lot instead of array#uniq in order to push only uniq items into a data structure.
  4. Module: Benchmark: Provides methods to measure and report time used to execute the code. When I wasn’t sure if I was just being inefficient or stuck in an infinite loop, I’d use Benchmark.
  5. #each_with_index: Oh, God. What would I do without #each_with_index? This method allows you to do what each does but also keep track of the index you are at in the array.
  6. Class: Digest.hexdigest: Returns the hex-encoded hash value of a given string, helpful for the cyber security questions.
  7. #zip: takes one element from an array and merge the corresponding elements from each array, zipping them together.
  8. Rubular: a website that allows you to play around with Ruby regular expressions.
  9. Handling of bitwise operators (binary numerals at the bit level) showcased well in this article.
  10. #sub, #match, #gsub, #inspect, #take and #name_captures: all ways to handle regular expressions and find string or digit matches inside a particular string. #name_captures even returns a hash! Figuring out how to use all these correctly was a major hurdle and felt great to overcome.

There are many more awesome Ruby things I learned in this process. I also enjoyed comparing Ruby solutions with other languages. I would love to return to these one day and solve them in another language (or two!).

5. Scalability a.k.a. “THERE’S A PART TWO?!”

A great thing about AoC is that every puzzle had a second part. That second part was either easy or hard to solve, usually based on how you set up the first part. With that in mind, it was always helpful to not be hack-y in your solution to the first part. This caused me to spend more time thinking through what the puzzle was asking than brute force hacking.

6. ❤ pry & irb ❤

This post is dedicated to irb and pry. I love you. And you are my best friends in Ruby. Thank you. You will find commented out (and a few stray not-commented-out) binding.pry’s in all of my code. Debugging was key to finishing these puzzles.

Jon Stewart, Comedy, and Craft

A short thought.

So I was on a few planes this week and I had a lot of down time to read and think. I finished Andy Weir’s The Martian. It was okay. Should make for a good movie. Anyway, I got to engage in one of my favorite down-time past-times: listening to a gajillion billion podcasts. Besides NPR, The Read, Another Round, Call Your Girlfriend, Slate, etc. (all the favorites), I decided on a whim to search for “Jon Stewart” in podcasts and dug up some old interview’s he did on Fresh Air and Bill Moyer’s show. I have watched Jon Stewart for as long as I’ve been interested in politics… so for the whole tenure of his time on the Daily Show. I have always felt a strong connection to his righteous anger on issues of corruption in the media and in politics. Sad about his leaving the show, I decided to listen to him speak about comedy and his time early on in the show. In this search, I came across an interview he did with Dave Davies in 2004 that struck a chord for me. Here is an excerpt from their conversation:

DAVIES: And you decided to go to New York and do standup […] And at first just got brutalized, as people do. And I’m wondering – you know, there are lots of people who are funny, that make their friends laugh, make their families laugh […] I mean, you were so funny, you had that brain working that way. What was it you didn’t know?

STEWART: What was I didn’t know about which?

DAVIES: About why didn’t it work? Why is being funny with your friends not the same thing as…

STEWART: Well, because it’s a craft, you know? It isn’t – there’s a big difference between having an analytical mind and being a good scientist. There is a craft to learn. And that was the biggest lesson is that it takes – again, it’s that idea of turning obnoxiousness into wit or comedy. You know, creating something from nothing is different from just being reactive at a bar. And you have to create the atmospheric conditions for comedy. Comedy is oddly enough very fragile and can be thrown off by, you know, a glass breaking or somebody talking or – you, know, there’s a lot of different elements to it that – and construction of a joke – you know, you have to create – one of the things about being funny life is the premise is already there.

This completely encapsulates my motivations and thinking as I delve further into projects in programming (and as I try to defend this divergent path to friends and family as well). There are lots of people who are sharp, who are analytically minded, who are the most creatively critical in a classroom. I was one of those kids. I’m an analytical person. However, being smart or analytical is exactly like being funny around friends in Jon Stewart’s case. There is a big difference between the potential and the profession. I think that in this year after my graduation, I want to build craft. What a word. Craft. 10,000 hours. I want to work hard at something that is intellectually exhausting and come out the other side two, five, ten years down the line, with a craft. As Stewart says, the biggest thing to learn is taking that energy and potential and turning it into something, producing something, and building something, and then channeling that something positively. I see so many similarities between comedy (purely, the most intricate and nuanced facet of language itself) and code similar to how I saw similarities between linguistics and code. And that comes down to craft. Craft is not a manual. It is not something that can be taught straightforwardly. It is an expert intuition, always moving and evolving, it is nuanced in its execution. When this craft is tuned and focused and then let grow through improvisation, it can be amazingly beautiful.

Wow, I got to go code some more.

tumblr me8m1h0m161qcmnsuo1 400 All the Jon Stewart GIFs you'll need as he leaves 'The Daily Show

Design and Creativity

I’m currently taking an intermediate HTML/CSS class with Girl Develop It. The class is being held at Adobe in Seattle. Wow! That office space is beautifully designed (I mean, of course, but still) and taught by the awesome Marcy Sutton who is basically everything I want to be later in my career in programming. I just talked about this for my Ada application video, but five years into my career I would love to find my place in my coding community, give talks, be an educator and mentor, and have a larger effect on the community when it comes to accessibility and inclusivity for others. Marcy is doing all that and is awesome.

I enjoyed the last HTML/CSS class I took with GDI and my websites are starting to move out of the 90s and into the modern era with a little CSS3 help: Screen Shot 2015-07-14 at 7.55.54 PM

And a 3-column design looks so pretty (ignore me and the donut)!!!:

Screen Shot 2015-07-15 at 8.49.54 AM

However, the class has me thinking a lot about “design” and what that means and if I would be good at doing it or even like it. I am not one of those people who think anyone and everyone can design or that art is not a deeply rooted praxis. This comes from being raised by an architect and having several industrial and graphic designers in my family. I have heard a lifetime worth of arguments over hexcodes, shades, good design practice, and the difference between all sorts of triangle shapes — 30 degrees is NOT 31 degrees and that you would insinuate that is an insult. I find design compelling, I do like art, but I’m not sure it’s really my strong suit. I have always liked spatial problems. Or maybe it’s just math — any problem with multiple variables and a restraint. I often imagine time constraints and word counts in terms of finite space.

I just don’t know if tweaking CSS and HTML to hack design on a website is exactly what gets me excited. Tweaking databases and data structures so that we get different and more accurate interpretations of results however… I could do that all day. I don’t mind cleaning data, because I love breaking down something large and complex. I think it’s so important to appreciate design and know how it works though and I understand in the abstract sense that the “front end” is not only design. I am excited to learn more about the whole array of computer programming topics.

I wrote a philosophy paper once in undergrad about Martin Heidegger’s Building Dwelling Thinking, which argued for carefully inclusive design of public spaces. Heidegger begins his book stating

We attain to dwelling, so it seems, only by means of building. The latter, building, has the former, dwelling, as its goal. Still, not every building is a dwelling. Bridges and hangars, stadiums and power stations are buildings but not dwellings; railway stations and highways, dams and market halls are built, but they are not dwelling places.

In my head right now, you could so easily replace “building” with “web app” and “dwelling” with “webpage” where it exists through the browser. We attain to an accessible webpage only by building but definitely not everything we build is accessible.

Design is so important. Just learning a few basics, like what a “hero” (large header at the top of a website) is and how to alter it to look good, what SVG’s are and why they are better than png’s, and all sorts of best practices that will make your content accessible to everyone. At one point Marcy told us, “You don’t need to know how to create tools from scratch, but just being able to alter a SVG file is helpful.” I believed it. Having a birds eye view of design will definitely make me a better programmer no matter what part of the process I find fits me best.

I’m so thankful for organizations like Girl Develop It that go out of their way to offer classes at discounted rates for people who can’t afford General Assembly or Code Fellows. They are helping women like me to be more informed about the field as a whole and introducing us to really cool spaces like Simply Measured and Adobe in Seattle. I would definitely recommend looking into it if you are interested. They are very welcoming and have scholarships to their classes.