Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Adding a helper function for each specific page does seem like a code smell in this case. It may not always be a problem if you were referring say <code>user.second_wall</code> very often and needed a quick way to get to it. However, by linking each such function,</p> <pre><code>read_wall -&gt; second_wall -&gt; third_wall -&gt; fourth_wall </code></pre> <p>it will become incrementally hard to expand and maintain this. Maybe have a base function that can retrieve the wall posts given any user and the desired range.</p> <pre><code>get_wall_posts(user_id, range) </code></pre> <p>To get the first 100 wall posts, and mapping the id's would look something like,</p> <pre><code>first_100_posts = get_wall_posts(some_user, 0...100); first_100_ids = first_100_posts.map { |post| post['id'] } </code></pre> <p>One of the most important part of refactoring is to give good names to identifiers. Names such as <code>var</code> and <code>iterate</code> usually don't say much about the code. It is similar to, if not worse, than comments like,</p> <pre><code>// increment i by 1 i++; </code></pre> <p>Consistency is just as important. Groups of methods that do similar things should be named in a consistent manner. <code>read_wall</code> and <code>second_wall</code> seem to have a disconnect for me because the verb <code>read</code> missing from the other methods. <code>read_second_wall</code> sounds like a better name, and more inline with the rest.</p> <p>Another thing to consider in mind with the current design is object consistency. Currently some of the methods are linked by a process (getting the first 100 or 4 pages worth of posts) and not by their individual role, making them dependent on each other. Calling <code>second_wall</code> without calling <code>read_wall</code> will yield different results because the <code>result</code> property has not been initialized yet. That can result in difficult to find bugs because there is another dimension to keep track of - whether object are used in the order expected. </p> <p>Try to limit the side-effects of functions as much as possible. If an objected must be used in a certain order, then use the <a href="http://en.wikipedia.org/wiki/State_pattern" rel="nofollow"><code>state</code></a> pattern or anything similar to ensure that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload