dry

DRYing up Rock Paper Scissors

北慕城南 提交于 2019-12-20 05:31:15
问题 I'm a novice ruby programmer and although this code works, I'm wondering how I can improve it. I have very limited knowledge on lambdas and procs and the like, but any advice would be great. Is there any way to simplify the if else statements in each case? Also, is there any alternative way to the case statement skipped instead of making almost the entirety of the code one big if else statement? def rps(roll) roll_ops = ["rock", "paper", "scissors"] pick = roll_ops.sample result = nil if roll

If WCF is in a MVC application, should it use the controller to access the database to keep 'DRY'

老子叫甜甜 提交于 2019-12-19 10:41:50
问题 I have an MVC application that accesses SQL and Windows Azure. The logical flow looks like this: Person <--> View <--> Controller.ConvertPersonHere(x) <--> StorageContext.DoDataAction <--> AzurePersonTableEntity ConvertPersonHere is the answer to this Stack Overflow question and it converts the Model entity to the Storage entity public class Person { public string Name {get;set;} public int ID {get;set;} } public class PersonEntity : TableServiceEntity { public string Name {get;set;} public

Rails: Calling one Model from another Model. Why is this not possible?

点点圈 提交于 2019-12-19 04:15:11
问题 I have the following Model... class Room < ActiveRecord::Base belongs_to :hotel belongs_to :layout has_many :visits validates :number, presence: true validates :rate, presence: true validates :smoking, presence: true def self.rooms_with_smoking(smoking) self.where('smoking = ?', smoking) end def self.occupied_rooms(from_date, to_date) #24-26 self.joins(:visits).where('date >= ? and date <= ?', from_date, to_date).uniq end def self.vacant_rooms(from_date, to_date) self.where.not(id: Room

Rails: Calling one Model from another Model. Why is this not possible?

亡梦爱人 提交于 2019-12-19 04:15:11
问题 I have the following Model... class Room < ActiveRecord::Base belongs_to :hotel belongs_to :layout has_many :visits validates :number, presence: true validates :rate, presence: true validates :smoking, presence: true def self.rooms_with_smoking(smoking) self.where('smoking = ?', smoking) end def self.occupied_rooms(from_date, to_date) #24-26 self.joins(:visits).where('date >= ? and date <= ?', from_date, to_date).uniq end def self.vacant_rooms(from_date, to_date) self.where.not(id: Room

How to reuse a large query without repeating it?

无人久伴 提交于 2019-12-18 14:53:42
问题 If I have two queries, which I will call horrible_query_1 and ugly_query_2 , and I want to perform the following two minus operations on them: (horrible_query_1) minus (ugly_query_2) (ugly_query_2) minus (horrible_query_1) Or maybe I have a terribly_large_and_useful_query , and the result set it produces I want to use as part of several future queries. How can I avoid copying and pasting the same queries in multiple places? How can I "not repeat myself," and follow DRY principles. Is this

Using async await when implementing a library with both synchronous and asynchronous API for the same functionality

冷暖自知 提交于 2019-12-18 02:46:45
问题 I've got a few questions about how to provide both synchronous and asynchronous implementation of the same functionality in a library. I am gonna ask them first and then provide the example code below (which is actually quite a bit, but in fact it's quite simple). Is there an approach to avoid violating the DRY principle? Consider the implementations of JsonStreamReader.Read , JsonStreamWriter.Write , JsonStreamWriter.Flush , ProtocolMessenger.Send , ProtocolMessenger.Receive and their

Is duplicated code more tolerable in unit tests?

China☆狼群 提交于 2019-12-17 15:44:15
问题 I ruined several unit tests some time ago when I went through and refactored them to make them more DRY--the intent of each test was no longer clear. It seems there is a trade-off between tests' readability and maintainability. If I leave duplicated code in unit tests, they're more readable, but then if I change the SUT, I'll have to track down and change each copy of the duplicated code. Do you agree that this trade-off exists? If so, do you prefer your tests to be readable, or maintainable?

RAII wrapper for OpenGL objects

南楼画角 提交于 2019-12-17 15:38:32
问题 I want to write a simple RAII wrapper for OpenGL objects (textures, frame buffers, etc.) I have noticed, that all glGen* and glDelete* functions share the same signature, so my first attempt was like this: typedef void (__stdcall *GLGenFunction)(GLsizei, GLuint *); typedef void (__stdcall *GLDelFunction)(GLsizei, const GLuint *); template <GLGenFunction glGenFunction, GLDelFunction glDelFunction> class GLObject { GLuint m_name; public: GLObject() { glGenFunction(1, &m_name); } ~GLObject() {

Is it possible to share a masterpage between MVC and webforms?

99封情书 提交于 2019-12-17 15:25:16
问题 I am adding MVC to a project that has MANY legacy webform pages. This works fine. However, I currently have a separate masterpage for MVC and for the webforms. The two master pages produce essentially identical output. I'd really like to kill the webforms one and just use the MVC master page with all my pages and stay DRY. Not being DRY has already bitten me a couple times when I forgot to change both. I tried doing the obvious way and just pointing the webform content page's MasterPage

Why does Flash CS3 require you to specify the base class when exporting for actionscript (as3)?

这一生的挚爱 提交于 2019-12-14 04:06:46
问题 In the library, right-click on a movieclip that you have written an ActionScript class for and select "Linkage...". Notice that the "Base class" field is not empty (it can't be). It's likely to be flash.display.MovieClip , but it could be something else, depending on what your class inherits from. This base class field is only required when publishing for ActionScript 3. So can anyone tell me why Flash CS3 insists on me providing the base class in both the ActionScript file and the Linkage