code-reuse

How can I promote code reuse in a manner similar to mixins/method modifiers/traits in other languages?

若如初见. 提交于 2019-12-03 12:40:23
I'm working on some code that interfaces to a database schema that models a persistent graph. Before I go into the details of my specific question, I thought it might help to provide some motivation. My schema is around books, people and author roles. A book has many author roles, where each role has a person. However, instead of allowing direct UPDATE queries on book objects, you must create a new book, and make modifications to the new version. Now, back to Haskell land. I am currently working with a few type classes, but importantly I have HasRoles and Entity : class HasRoles a where -- Get

Good Idea / Bad Idea Should I Reimplement Most Of C++? [closed]

人盡茶涼 提交于 2019-12-03 09:30:36
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Recently, I've got a dangerous idea into my head after reading this blog post. That idea can be expressed like this: I don't need most of what the C++ standard library offers. So, why don't I implement a less general, but easier to use version? As an example, using the STL

How to re-use a reusable app in Django

£可爱£侵袭症+ 提交于 2019-12-03 08:40:09
问题 I am trying to create my first site in Django and as I'm looking for example apps out there to draw inspiration from, I constantly stumble upon a term called "reusable apps" . I understand the concept of an app that is reusable easy enough, but the means of reusing an app in Django are quite lost for me. Few questions that are bugging me in the whole business are: What is the preferred way to re-use an existing Django app? Where do I put it and how do I reference it? From what I understand,

Why shouldn't we wrap every included Android XML layout in a <merge> pair?

别等时光非礼了梦想. 提交于 2019-12-03 07:21:55
As a follow-up to this question , I can't think of any good reason why I shouldn't wrap every included XML layout in a <merge> pair. Which then leads me to wonder, why didn't the ADT team just make this the default behavior? Is there any case where one wouldn't want this behavior? Incidentally, the explanation in the Android documentation of the <merge> tag is worse than the wording in the worst legal agreements: The <merge /> tag helps eliminate redundant view groups in your view hierarchy when including one layout within another. For example, if your main layout is a vertical LinearLayout in

How to model mixins / multiple interfaces in Haskell?

断了今生、忘了曾经 提交于 2019-12-03 06:14:51
I came across this question on modeling inheritance in Haskell and it reminded me that I have a little more complicated version of the same problem. I'll adopt the example from there because it's easier than thinking up my own. Suppose your program contains a number of types: data Camera = Camera ... data Light = SpotLight ... | DirectionalLight ... data Object = Monster ... | Player ... | NPC ... Now you want to implement some basic physics, so you want them all to have a position and a velocity, say of some type Vec3 . One way to do this is to declare a Physical typeclass with pos and vel

How to organise large code files?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 03:21:54
I am increasingly aware that my code in any single file can often span hundreds of lines quite easily and although I know the implementation might be sound, it still feels messy and unorganised. I understand that there are situations where a lot of code is neccessary, but whats the best way to organise it all? I've thought about separating variables from methods, private s from public s and internals but I don't want to because I can't help thinking that the components of ONE class belong in ONE file. This whole thing is compounded when I'm working with the codebehind of a WPF window, which

Coding Priorities: Performance, Maintainability, Reusability?

被刻印的时光 ゝ 提交于 2019-12-03 03:13:44
This came about mainly due to answers to SQL questions. UDF's and Sub Queries are intentionally omitted because of performance. I didn't include reliability not that it should be taken for granted, but the code has to work. Does performance always come first? So many answers are provided with performance as the main priority. My users seem to be more concerned with how quickly the code can be modified. So a report takes 15 seconds instead of 12 to run. They can live with that as long as I'm not making excuses for not providing solutions. Obviously if the 15 seconds turns into 15 minutes, there

Good Idea / Bad Idea Should I Reimplement Most Of C++? [closed]

好久不见. 提交于 2019-12-02 23:51:50
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Recently, I've got a dangerous idea into my head after reading this blog post. That idea can be expressed like this: I don't need most of what the C++ standard library offers. So, why don't I implement a less general, but easier to use version? As an example, using the STL spits out reams of incomprehensible and mangled compiler errors. But, I don't care about allocators, iterators

How do I create and maintain a code reuse library?

落爺英雄遲暮 提交于 2019-12-02 19:36:21
I am trying to setup a repository of reusable code. I was thinking about having each reusable code module have a certain “Maturity Level” rating. The rating would be defined as the level at which a reusable code lies within a certain set of requirements. The highest maturity level will be the highest degree of standard across a predefined set of requirements. For example: Level; Requirements; Description Level 0; Code is legal to use; Is the code legal to use in commercial industry/across multiple contracts/etc? Level 1; Base codeline and meets level 0 requirements; Prototyped code, 3rd party

Derive overloaded operator, but operate on same types only

你。 提交于 2019-12-02 07:39:21
Suppose I have a base class and two classes derived from it: class Base { protected: double value; public: virtual ~Base(); Base(double value) : value(value) {} Base(const Base& B) { value=B.value; } Base operator+ (const Base& B) const { return Base(value+B.value); } }; class final Derived1 : public Base { public: Derived1(double value) : Base(value) {} }; class final Derived2 : public Base { public: Derived2(double value) : Base(value) {} }; I want to accomplish the following: int main(int argc, char *argv[]) { Derived1 a = Derived1(4.0); Derived2 b = Derived2(3.0); a+a; // this should