C# Console Programming Lesson 5
Archive (40 Kb) contains PDF version of lesson and all pertinent source code files. Return to Lesson 5 content.
View On WordPress

#batman#dc#dc comics#bruce wayne#dick grayson#tim drake#dc fanart#batfam#batfamily



seen from United States

seen from United States
seen from United States
seen from Hong Kong SAR China
seen from United States

seen from United States

seen from Singapore

seen from United States
seen from Israel

seen from Finland

seen from Israel
seen from Namibia
seen from Israel

seen from Italy
seen from Egypt
seen from China
seen from United States
seen from Yemen
seen from United Kingdom

seen from Malaysia
C# Console Programming Lesson 5
Archive (40 Kb) contains PDF version of lesson and all pertinent source code files. Return to Lesson 5 content.
View On WordPress

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Helper Methods: Open Up The Door
Today in class, our instructor told us he'd like us to limit each method to around 7 lines of code. This made sense, based on our understanding of the single responsibiliy principle. Nonetheless, it was alarming -- what if fulfilling that responsibility required several steps? Well, that's when I realized I needed somebody - namely, a helper method.
A helper method does pretty much what it says on the tin - it is a method that helps another method perform it's task. You can use one to extract complicated logic to make a method more readable. You can also use one because you know you're going to be using that functionality frequently (ie: >=3 times).
In a way, the entire premise of Ruby on Rails is that it generates a giant pile of useful helper methods for developers to get their projects off the ground. For example, both "form_for" and "form_tag" are Rails helper methods that take in erb code and create clean HTML.
Rails also encourages that we write our own helper methods. To that end, it comes packaged with a class method, called helper, that declares another method (or a module) is available to help us with anything to do with that class.
Here's an example of how helpers cleaned up my code. I've been working on a side project I'm calling Movie Notebook. One of the goals of this project was to practice creating a functional app, from the ground up, without any instructions or expectations from teachers. Part of that, I knew, would involve writing my very first rspec test suite.
While creating my tests, I realized that I was writing @movie = Movie.create(et cetera) an awful lot. Since I already had five different spec files, I decided that I would create a module that would, among other things, create a movie for me to edit. Check out my module below.
And here are some before and after shots of my tests:
In fact, to get rspec to work at all, you'll need a helper--it's a configuration file found at (in my case) /spec/rails_helper.rb. So it was very easy to include my module in all my extant specs and any I create in the future. I just went into my "RSpec.configure do |config|" block and added "config.include MovieHelper" (though if I'd wanted it just for controller tests, I'd've added ", :type => :feature").
today’s title was courtesy of the Beatles
W4D5 - Partials and Helper Methods
Project
Reddit Clone! Most people use reddit to waste time. We used it to learn about partials and helpers, and to practice authentication again.
MVC
Rails separates its logic (for the most part) into the model, the view, and the controller. The controller is the main workhorse. The model temporarily provides an object oriented version of part of the database. The view is just a simple document to show to the user after all the work is done.
Depending on the state of the web app and the user's loggin status, we may want to show different things on a given page. Unfortunately, a natural tendancy is to write more and more of this logic in the view. This makes the view code ugly and bloated.
Partials and Helper Methods
Partials and helper methods to the rescue! Helper methods can be organized and stored in a different file and called with a short descriptive name from the view. This separates different logical pieces, making them easier to work with and debug. Likewise, partials can store large chunks of code that are repeated in several different views accross the website. When one needs to be edited, they all can be edited in one place!