![]() |
| ||
| Artificial System Clock Code review critique Hi - I'm very new here (1st post). I read the introductory docs, and looked at the categories, but I didn't see a specific place for posting code for review/critique. My apologies if this is not the appropriate place to do that... Here is some code I am hoping to get reviewed/critiqued by people who know Ruby. I don't know squat about Ruby, but I am pretty familiar with modern OO lang's (C++, Java, C#, PHP, etc.), and I wrote this after reading a few tutorials. It is an implementation of an Artificial System Clock (ASC). The idea is that you will use the getSystemDate method of this class everywhere in your app. that gets the date/time directly. Then you can change the date-time context for the whole app. for testing purposes. When in "channel" mode, it will go fetch the date-time value from TimeChannels.com, so that you can integration-test with multiple interfacing apps. all on the same shared ASC value. Here's the TimeChannels class I wrote in Ruby: require 'date' Many thanks in advance to all who reply... John |
| ||
| Re: Artificial System Clock Code review critique I have a suggestion, I think your code need a exception handler when your internet connection is lost. |
| ||
| Re: Artificial System Clock Code review critique Though I'm no Ruby expert, here are a few suggestions: if (result.nil?)can also be written as: return Time.now if result.nil? = Instead of using @@tcMillisecondMode = "false", why not just use @@tcMillisecondMode = false? = Your ASC state can be better represented using Ruby Symbols. = In Ruby in absence of a returnstatement, the value of the last expression evaluated is returned hence the method: def TimeChannels.getHTTPContent(url)can be replaced by: def TimeChannels.getHTTPContent(url)though as already mentioned, handling exceptions in case establishment of a connection fails should come first. = The Ruby way of naming variables and methods is *not* to use camelCase but use under_scores; though it's a matter of taste. However it pays to follow and use the conventions used by the community in general to facilitate easier understanding of others' code and vice-versa. In case you require a more in-depth review, feel free to post your code on the official ruby forums and you'll surely get more feedback. HTH -sos |
| All times are GMT -4. The time now is 7:32 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC