January 28, 2015 by Daniel P. Clark

Learning by Teaching

I grew up in a home-school family.  That being the case there were times where my mom was learning as well while still teaching.  There are many times where the teacher will learn from the student.  As we learn we can both sharpen our own knowledge and refine it by teaching what we learn to others.  For this reason I highly recommend that you write and share your experiences as you learn and move forward.  Share what excites you about what you’ve learned.  Share what was difficult to overcome and what helped you break through it.  Share the light you receive.

I love programming.  It’s fun, it’s intriguing, and I have mental energy and focus with all things new and challenging.  I like to share things in the way I learn.  I prefer to focus on the method and pattern of learning rather than just the facts.  Our best tool for the job is our mind.  If we can improve the way our mind works then everything is affected positively by it.

In my recent blog post The 500 Millisecond Rails Partial I received some of the best, well thought out, feedback I’ve ever received.  It may have something to do with the amount of effort I put into the blog post.  Who’s to say though.  I will post two of the feedbacks here for illustrative purposes.

While this article is pretty well written, there are some things that are quite strange with the methods used by the author.

First of all, caching the unencrypted e-mails somewhere in memory completely defeats the purpose of encryption in the first place. If you use encryption, you do this because you don’t want to store the plain text. Storing it plainly somewhere in memory is a security risk, as we have seen with the heartbleed bug.

Secondly, pagination should be the very first thing the author should have tried to speed up the partial. Loading less objects results in quicker page loads.

Third, using current_user.emails.map initializes an Email object for every email. The author then creates a new object with some results from these objects, resulting in more objects being initialized and more work for the GC. Just working with the Email objects might make the page load quicker than it was with the extra objects.

Finally, instead of using caching in the model which creates tight coupling, it would be better to use Russian Doll caching in the views and bypass the database entirely.


He’s right about all of his points.  And I was able to see and understand more now that he has taken the time to write his helpful critique.  I had just learned about caching, and the idea of Russian Doll caching.  Paging had occurred to me later in the writing as I hadn’t been in practice of using it.  I am grateful to receive any and all feedback that will both better me, and all else who read it.  Here’s another such feedback I received for that same article.

So I plugged OpenStruct in and that did the trick. No more “Singleton cannot be dumped!” errors. Just OpenStruct.new( id: i.id, email: i.email, created_at: i.created_at ) and now my Array of unencrypted Objects function just like query result Objects for my view.

And now you have another problem: OpenStruct dumps the Ruby method cache.

Like the other commenter said, caching unencrypted data basically defeats the purpose of caching; your cache becomes a point of attack.

This kind of progress is great, though. Tracking down slow spots in your application doesn’t have to be too hard, though; one of my favorite tools is ruby-prof with kcachegrind. You can learn a lot not just about your app, but what the libraries you use are doing, too.


And I’ve gained even more insight.  I followed the links provided and enjoyed this new treasure trove of knowledge.  I hadn’t heard of Ruby dumping method cache for anything before.  So to read up on it I now officially “Level’d up!”

On a side note where my coding journey went into that post, I ended up throwing out all that code.  It was a wonderful learning experience.  I was supremely proud of some of the cool tricks and designs in my code.  But I did have some signs that trouble was ahead on that path.  I was even feeling it in my gut.  So I was actually relieved to let that code go.  Not only that but I found a Ruby gem that would handle what I really needed.  That gem is acts-as-messageable.  I may write about it; we’ll see.

These aren’t the only well written inputs I’ve received on my blog.  And I encourage any and all input.  People can learn just as well from a comment that looks like “You’re wrong, see this article: 5 points on why you’re wrong“.  Whatever the way you choose to reply can be helpful.  It does help to use diplomacy in any “corrections” given.  Complements are best given at the beginning as a general rule… it’s a door opener.

When you write your own blog posts know that you will get both good and bad feedback.  Don’t allow the “down voters” to influence your mood or state of mind.  Think about the bigger picture.  You are helping others, and there are those who will do the same for you.  Besides you can think that some of those down voters are just bots programmed to down vote everybody ;-).

Life for us is a journey.  Joy is experienced in the journey, that is, the present.  You can choose to be taxed by something difficult, or you can change your perception and welcome the Ninja Warrior obstacle course that you will conquer with style.

Learning is fun, life is fun.  If this isn’t how you perceive things then I want to open your understanding.  Our perception is our own, and largely of our own making and direction.  We need to put in good so that good may flourish.  For your mind I will recommend to you the first positive speaker I encountered who changed my whole world view and lead me on a path without “Stinken Thinken”… that’s right.  I’m talking about Zig Ziglar.  Get his book “See You at the Top” and read it.  You’ll be glad you did.  It’s broken into short stories so it’s not a tedious read.  As a matter of fact it’s probably one of the most enjoyable books I have ever read.  I’ll be recommending more books another time.


Perception makes the journey.  Teaching and sharing what you learn are empowering and worthwhile.  In the end it’s not all about “learning”, but it goes beyond that into “connecting with others”.  People are the spice of life.  Be active in helping others whether by teaching what you’ve learned or otherwise.  But I do encourage you to pursue what you’re passionate about, share that journey, and in so doing grow, and those with you.

Don’t let any “reasons” hinder you.  Cast aside doubts.  Be the person you would rather be.  As Zig Ziglar has said “You were designed for accomplishment, engineered for success, and endowed with the seeds of greatness”.  So be confident and be faithful in the small things.

As always I hope you found this both enjoyable and insightful!  Please comment, share, subscribe to my RSS Feed, and follow me on twitter @6ftdan!

God Bless!
-Daniel P. Clark

Image by Duane Schoon via the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 Generic License.



  1. Caleb Nei
    January 28, 2015 - 10:44 pm

    Thanks for the good words, Daniel.

Leave a Reply

Your email address will not be published / Required fields are marked *