Best ruby idiom for "nil or zero"
I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like: if (!val || val == 0) # Is nil or zero end But this seems very clumsy. ...
I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like: if (!val || val == 0) # Is nil or zero end But this seems very clumsy. ...
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a specific question regarding Actions. Most of the pages have exactly one Action, and the processExecute() methods are hideous monsters (very long and tons of nested if statements based on request parameters). Given that Actions are an implementation of the command...
I'm working with a JavaScript API where most of the functions are asynchronous. The API is the WebKit JavaScript Database API which is a binding to a subset of functionality to manipulate SQLite3 databases. I understand the design decision to make things async as to not block and provide a responsive user interface. In my situation I ...
I have a class on which I want to allow several (~20+) configuration options. Each option turns on or off a piece of functionality, or otherwise alters operations. To facilitate this, I coded a separate options class with default values. However, I had to litter my code with guard conditions to determine how methods should behave. I am ...
How do large web sites which cannot be completely stateless achieve extreme scalability at the web tier? There are sites like ebay and Amazon, which cannot be completely stateless, as they have a shopping cart or something like that. It isn't feasible to encode every item in the shopping cart into the URL, nor is it feasible to encode e...
I'm trying to get my head around SPL iterators and I've come up with 2 ways to handle it. I see the first version to be less complicated but the second version has composition feel to it (I think). What am I not seeing is which one is preferable over the other? Or am I just over complicating this? Here are my thoughts: The object impl...
When should I continue to make derived classes, and when should I just add conditionals to my code? eg for a missile class Object; class Projectile : public Object; class Missile : public Projectile; class MissileGuided : public Missile; Or should I implement that last one in the missile's code? void Missile::Update() { if(homin...
It is common knowledge that built-in enums in C++ are not typesafe. I was wondering which classes implementing typesafe enums are used out there... I myself use the following "bicycle", but it is somewhat verbose and limited: typesafeenum.h: struct TypesafeEnum { // Construction: public: TypesafeEnum(): id (next_id++), name("") {} ...
Scenario: (If anyone has answered/viewed my questions recently this will be somewhat familar) I have 3 different web services which expose a set of objects that have commonality. I've written wrapper classes and conversion logic using generic methods to change between the intermediary objects and the service object. I have an interfa...
Is there a way to write an enumeration that can be extended. I have several methods that I would like to alway have available for my enumerations. For example I use an enumeration for my database fields. I include the actual field name in the database. public enum ORDERFIELDS { OrderID("Order_ID"); private String...
I just recently really truly groked dependency injection and the wonder of the Decorator design pattern and am using it all over the place. As wonderful as it is however, one thing that I've been having difficulty with is naming my decorator classes so I would just like to know what others do. Do you always append the word Decorator? ...
Say you have a web form with some fields that you want to validate to be only some subset of alphanumeric, a minimum or maximum length etc. You can validate in the client with javascript, you can post the data back to the server and report back to the user, either via ajax or not. You could have the validation rules in the database and ...
I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application consists of two modules at the moment: Left Panel to browse a tree and select a node Main Panel to show the content of the selected tree node. I want to keep these two modules seperated, but when I select a node in the Left Panel I need t...
It seems that the decision to make your objects fully cognizant of their roles within the system, and still avoid having too many dependencies within the domain model on the database, and service layers? For example: Say that I've got an entity with a revision history, and several "lookup tables" that the data references, your entity ob...
I like Steve Yegge's Prototype Pattern example and decided to whip up a quick proof of concept example. However, I didn't really think things through. While it is great for dynamically specifying the behaviour of objects and is an easy solution to Steve's opinionated elf example, I'm still trying to work out the best way to handle inst...
The glorified global variable - becomes a gloried global class. Some say breaking Object Oriented Design. Give me scenarios, other than the good old logger where it makes sense to use the singleton. ...
What implementations of the Prototype Pattern exist on the Java platform? A prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype based programming: Prototype-based programming ...
Why should I choose to use one instead of the other and in which cases? I mainly focus on desktop applications and personally speaking I do find the humble dialog box more easy and natural to use. ...
I have looked over the Repository pattern and I recognized some ideas that I was using in the past which made me feel well. However now I would like to write an application that would use this pattern BUT I WOULD LIKE TO HAVE THE ENTITY CLASSES DECOUPLED from the repository provider. I would create several assemblies : an "Interfaces...
When I first discovered the Strategy pattern, I was amazed of the seemingly endless possibilities it offered to me and my programs. I could better encapsulate my models' behaviour and even exchange this behaviour on the fly. But the strategy could also be used to to provide traits and payload to the containing object - data that was decl...