View Single Post
Old 10-23-2012, 05:48 PM   #136
GNS
Senior Member
 
Join Date: Jul 2012
Drives: .
Location: Ontario
Posts: 350
Thanks: 28
Thanked 223 Times in 105 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quote:
Originally Posted by shinigami052 View Post
Sorry but that was just horrid "programming".

if(news_day.isSlow()) report(Turbo_BRZ);

would be better...just sayin'

Quote:
if(news_day.isSlow()) report(Turbo_BRZ);
You're setting yourself up for multiple if-statements, or cascading
if-statements with this method of determining if a news_day is 'slow'
or 'fast'. *Since news_day is an object, you should be able to query
it and receive its current status with a single call, like so:

Quote:
// returns an integer, which can be compared against static ints
news_day.getDaySpeed()
Also, why is the Turbo_BRZ an object iself? *It should be more
generic, so that you can pass an object around without having to name
it according to the news that it contains.

Based on all of the above changes, perhaps your code can be rewritten
as such (still a snippet of code). *I have written it sequentially,
instead of breaking things up into methods.

Quote:
/**
* Variable declarations
*
*
*/

// NewsDay is an object representing a news day
// Here we are instantiating the object for today's news
NewsDay news_day = new NewsDay( System.Today() )

// ReportAggregate is an object that holds Report objects in a List structure,
// and provides functions to change their priority/order/etc around based on the
// attributes within the Report
ReportAggregate newsList;

// ReportItem is an object within ReportAggregate's List
ReportItem newsItem;

// Reporter is an object that queries a newsfeed/database to get current news,
// and it can also set news
Reporter autoReporter = new Reporter()

// The URL where the news will be posted
URL postedURL = "http://www.ft86club.com/forums/forumdisplay.php?f=23"


/**
* Do stuff
*
*
*
*/
newsList = autoReporter.getNewsForURL( postedURL )

if ( !newsList.isEmpty() )
* *newsList.sortPriority( news_day.getDaySpeed() )
* *newsItem = newsList.pop() *// pops first item off the List
* *autoReporter.setNewsForURL( postedURL, newsItem )
end

*(I still don't consider it perfect, it can be refined even further
and simplified even more). For example, autoreporter might be doing too much (things should be broken down into simple, focused and well defined operations).

The only real way to design a proper reporting system is to draw it out on a board (or use object design language to properly define objects and their relationships).

Bah.

Last edited by GNS; 10-23-2012 at 06:02 PM.
GNS is offline   Reply With Quote