instruction
stringlengths
34
19.9k
I am wondering if there are patterns, references or useful resources about how to implement objects that may have several equivalent representations. For example: Suppose I want to implement a Rectangle, and I will instantiate it using its length and width: class Rectangle: def __init__(self, length, width): ...
(I'm specifying this is a desktop application so people wouldn't refer specifically to web implementations of MVC). The title says it all pretty much. In an MVC structure - can the View ever hold a reference to the Model? Or should the Controller be used as a 'middleman' for communication between the View and Model - a...
Classes have 10-20 links with one another and you can't see anything in that mess of a diagram Unfortunately we finished coding already and if we change the class diagram we have to redo the whole thing
In my program, I have several class variables whose access specifier is known as private package. The default accessor specifier in Java is known as private package where it is accessible within the package which the class belongs to. For the UML class diagram , should I label these variables as public or private? I ...
To keep our house in order, I want to automatically assemble licenses for project dependencies in our documentation, rather than having to add them manually. Does anybody know a simple way to traverse programmatically a set of CSPROJ files and extract the license information for the referenced packages as a link or str...
According to Microsoft documentation, the Wikipedia SOLID principe article, or most IT architects we must ensure that each class has only one responsibility. I would like to know why, because if everybody seems to agree with this rule nobody seems to agree about the reasons of this rule. Some cite better maintenance, s...
Is there a specific term to call the process of modifying hard-coded codes into soft-coded codes? I have to report what I am doing to the Project manager, shall I just put "modifying hard-coded codes into soft-coded codes"? Example of "hard-coded codes" int random(){ return 42; } Example of "soft-coded codes" int rand...
We have quite a lot of places in the source code of our application , where one class has many methods with same names and different parameters. Those methods always have all the parameters of a 'previous' method plus one more. It's a result of long evolution (legacy code) and this thinking (I believe): "There is a met...
Correct me if I'm misunderstanding. Refer to the following sentence: Stack Overflow copied a key part of the Wikipedia database design. This turned out to be a mistake which will need massive and painful database refactoring to fix. The refactorings will be to avoid excessive joins in a lot of key queries. This ...
I am not quite sure, how to name my problem. But I will start with how I usually used git. I am working as a single developer on one git repository. Usually I make feature-branches from master, and merge them back into master, when the feature is finished. When meanwhile another feature-branch was merged into master, I...
In exercise 1-16 in The C Programming Language (K & R) it asks for us to: revise the main routine of the longest-line program so it will correctly print the length of arbitrary long input lines, and as much as possible of the text. From what I read here, I get the notion that the main routine is everything inside of ma...
Here's the situation: I have a "common" Data Access assembly that contains classes used in all my projects. Some of those are abstract classes that are only implemented by my data access layers for each project. In my projects I have a layered approach - separated data access, business layer, and UI. My data access ...
When you are working on a feature that depends on time... How do you organize unit testing ? When your unit tests scenarios depend on the way your program interprets "now", how do you set them up ? Second Edit: After a Couple of days reading your experience I can see that the techniques to deal with this situation usua...
From value point of view I see two groups of unit tests in my practice: Tests that test some non-trivial logic. Writing them (either before implementation or after) reveals some problems/potential bugs and helps to be confident in case logic is changed in the future. Tests that test some very trivial logic. Those test...
I am using redmine for project management and issue tracking. I was looking at the database tables and the underlying structure and was wondering if anyone who is experienced with database architecture can comment on the structure. I am concerned that once there are many users and hundreds (or thousands) of projects (e...
1 - Design my entities, ie (in python): class Account: def __init__(name, author): self.name = name self.email = email 2 - Design my repositories: (as interface) class AccountRepository: def add(self, account): """ @type account Account """ pass def find_by_name(self, name)...
I've just begun reading "The Art Of Unit Testing" by Roy Osherove, and while I'm mostly finding the material very helpful, he makes a statement about not using messages in your Assert statements. "Please never, ever, use this parameter. Just make sure your test name explains what's supposed to happen." My question...
Are closures considered impure in functional programming? It seems one can generally avoid closures by passing values directly to a function. Therefore should closures be avoided where possible? If they are impure, and I am correct in stating that they can be avoided, why do so many functional programming languages sup...
Ruby object has method/property: def tentakles_count 8 end JavaScript object has key/property: { justEnough: true } Now, when JavaScript gets serialised ruby object via XHR or WebSocket, developer has to use alien naming convention to access tentacles_count. The same goes for Ruby, when it gets json object POSTed, ...
I've been thinking about trying to get through the SICP again, this time well-armed with a better idea of what the SICP is meant to accomplish, and being older and wiser than my first attempt back in university. I've been told by old hands that the MIT Scheme is the only scheme I should think about using, and that oth...
I like both but I notice languages that use camelCasing for members sometimes need more adjustments when you want to edit your code. For example (in Python): node.customData() vs node.setCustomData() custom changes casing. It could be avoided if it was: node.getCustomData() In C# they will use PascalCasing for examp...
In basic networking, we talk about DNS servers, that they resolve human readable addresses (www.google.com) into an actual IP address. As far as I understand, at least using the basics, an IP address refers to a single device (say a router). Surely, www.google.com cannot be served up by one computer? How is www.google....
I've always thought that in typical MVC design it is bad practice to build & concatenate HTML strings in any PHP file or class that isn't strictly a template. I'm working on a large project with strict guidelines in place, and while it is forbidden to put any HTML code in the PHP controller, it is fair game to have PH...
I wonder why frameworks/libraries have their own helpers although they exist natively already. Let's take jQuery and AngularJS. They have their own each iterator functions: jQuery.each() angular.forEach() But we have Array.prototype.forEach. Similarly, jQuery.parseJSON() angular.fromJson() But we have the JSON.pars...
Could you tell me what is the goal of the MVVM pattern? What are the arguments or the reasons I can give to a team and product owner to respect and develop according to this pattern? I would like a simple answer. Something in one sentence or one word. Is it for maintenance security testing something else?
In our company we have a relatively long history of database backed applications, but have only just begun experimenting with dependency injection. I am looking for advice about how to convert our existing data access pattern into one more suited for dependency injection. Some specific questions: Do you create one acce...
According to DDD-principles I use factory-methods to create consistent objects and to ensure that the objects are in the right state. Now I'm in doubt about inner logic of setter methods. I'm tied up with an object, that's similar to the following code snippet, so let's take it as an example: public class UserCredentia...
I am self taught web developer. I do not have any computer science degree from university. I know HTML5, CSS3, Javascript, PHP and some Python. But I am having difficulties about being efficient. When I create a project, I am buried into files, folders, bugs and todoes. Because I am managing multiple projects at a time...
Two different teams (from different companies) are uniting to work on a communal open-source project. Agreeing on technical design is something we have no trouble with, but I'm struggling with tooling/workflow problems. I really like a BDD testing tool called phpspec (analogous to RSpec), whilst a lot of my teammates s...
In my domain I have an Account object. e.g. class Account { public string Number; public string SortCode; } Within the context of DDD, should this account object have an ID property? The ID would be a primary key, basically a database artefact.
I'm using a piece of commercial software where the server will reject any attempt to connect to it from a newer client. In other words, you can use version 8 of the client to connect to a v10.0 server, but not version 10.1 of the client. Obviously, this software is what it is. But why would it be designed that way? ...
Please consider a program with four classes: Class A, B, C and D. Classes A and B are subclasses of abstract super-class C. Class D is dependent on C. Meaning: It holds a C objectOfTypeC field. As we know, polymorphically the objectOfTypeC reference may hold objects of classד A and B. The value of this reference may ch...
I'm working on an ASP.NET MVC site (using Team Foundation Service for source control) that I've divided into a few separate projects under one solution: Project.WebAPI (Main entrypoint, contains "Views","Scripts" folders Project.Data (abstract interfaces for backend data access) Project.Data.SqlServer (concrete impleme...
I'm on my first bigger C++ project and find that I have some really long lines. My goal is to break them to 79 columns, but I do not really know how to do this in a neat way. Are there some guidelines to break lines like these: VectorHistogram::VectorHistogram(size_t bins, size_t cache) : bins(std::vector<double>(bins)...
I am working on a C# net micro framework project, in particular an I2C bus management/class. I have several different I2C devices each defined in separate classes which contain all of the devices' unique methods. In my case, I can only have ONE I2CDevice object "active" to communicate with and to switch to another I2C ...
I have a fairly simple data structure like this: create table project (id int auto increment primary key, name text); create table item (id int auto increment primary key, name text, project_id int not null, project_sort_index int not null, sort_index int not null, foreign key fk_project(project_id) r...
Does it violate the GPL v3 if I were to use a gpl licensed firmware with my closed-source hardware that I am selling? Or do both have to be open-source, or do I just have to make the firmware source freely available? Thanks!
I created and maintain an open source Android app. Recently someone offered to translate my app into several other languages. At the same time, development continues on the app which can sometimes add string resources which need to be translated. How can I ensure that the additional string resources are translated with...
I have a long experience in programming Java EE projects, but as I noticed most of the job I have done was with Transaction Script (anti)pattern. So I want to learn using a rich domain model, but then there is a question, shall Domain Object be depended on container/system services (such a persistence, mail, ...)? I ha...
Historically, I probably would have written a script (php or something) to loop through all spreadsheet rows and perform some calculations. I'm looking for a pure SQL solution on the presumption that SQL has better options than loops. How should I approach this problem while using a pure SQL approach? DATA OVERVIEW...
I'm confused about some of the notations of UML class diagrams. Pretty sure I know what Association means. Any relationship between instances of two classes, where an instance of one class needs to know about an instance of the second class in order to perform it's work - is an Association relationship. An Association...
I have a question how to design a stack without using list or array? This is one question that I want to think about as I want to better understand stack.
I wrote code, but I myself many times don't even understand the code i wrote. I heard people using "refactoring method" to help them to understand others' code. I just knew a very little about refactoring. That is using the combined key Alt Shift R in eClipse, but it will automatically change all the related code & thu...
A short summary of how we do branch managing: From the MASTER branch one or many feature branches can be made (for mid to long term development), when deploy-able changes have been merged to MASTER then release branches are made. Release branches are kept for maintaining deployed version until the next release occurs a...
We are having rich text editor in which we can insert html. if any input contains <style> tag then the css is applied to entire window. is it possible to restrict that CSS to be applied within <div> not entire window?
I just dropped production database. It happened because I used dbCreate = "create" instead of "update" in DataSource.groovy. I was changing some domain models and wanted to update the database. dbCreate value was empty string (""), and I accidentally changed it to "create" instead of "update". How could I prevent this ...
Has anyone started a project to do IOC at compile time (possibly using Roslyn or Linq MethodInfo emit)? My experience with IOC containers has thus far been great, baring a few small issues Many IOC containers are slow to start up, as much of the resolution logic occurs here It is often hard to ensure that resolution i...
I am coding and found it's pretty hard to come up with an elegant design for my app at the first attempt. First time I'm only about 40% happy, then I refactor it to code the same app a second time (almost start from scratch). Second time coding, I'm only happy about 60% happy, so I refactor it once more to code the ...
Recently I create a fork from an "open source project GPLv2" with different name. I make a major changes in source code and I gave a new name to the modified open source. I kept in the header of each source file the origin author copyright. And then I publish my new open source in github. is this behavior is legal acco...
I am working on a C# net micro framework project, in particular an I2C bus class. I have several different I2C devices each defined in separate classes which contain all of the devices' unique methods. In my case, I can only have ONE I2CDevice object defined and to switch to another I2C device, I have to change the I2C...
Currently my architecture is a monolithic block that handles a really specific duty. Now it needs to be generalized. Right now it handles a request and all processes (1 or many) associated to it. There's a class Request and a class Process and since it serves one specific duty this model was OK. Right now I need to s...
I'm pretty new to Haskell although I did some ML many moons ago. I'm trying to set up a deck of playing cards, shuffle them and then deal them. I have the deck and shuffle sorted (of a fashion) but I'm not sure what I'm doing after that. This is what I have so far: import System.Random import Data.Array.IO import Contr...
In the source code I'm evaluating (jarjar), there exists java code that can be used like this: JarJarTask fixture = new JarJarTask(); fixture.addConfiguredRule(new Rule()); fixture.execute(); Which will throw an exception like: java.lang.IllegalArgumentException: The <rule> element requires both "pattern" and "result"...
I had a discussion with a co-worker yesterday about design philosophy. The other coder is more experienced then me, and I fully admit that he is likely much better at properly automating his testing, which I'm just now trying to break sloppy habits. However, it seems that some of our dispute is a philosophical issues...
I am working on a project with several older programmer and we were doing up the documentation of the program when I had a heated debate with one of the older programmers regarding the term : Kilobyte. He wanted to stick to the old way of using Kilobytes to represent 1024 bytes as he said most programmers understood t...
Where I work we have our own system library, which pretty much is only wrappers around the STL, such as: template <typename T> class HVector { protected: std::vector<T> data; public: int size () const; //Only returns data.size() int custom(); //Some generic custom function that uses the data vector } Most ...
I have something of an annoyance in my Git workflow. I do the usual thing where I branch off master, into a branch called feature. I work on this feature branch for a while, meanwhile possibly master has commits of its own, which I might merge into feature. As I do this, I have a remote branch for feature (origin/featu...
I am trying to improve performance of my ASP.net Web Api by adding a data cache but I am not sure how exactly to go about it as it seems to be more complex than most caching scenarios. An example is I have a table of Locations and an api to retrieve locations via search, for an autocomplete. /api/location/Londo and th...
I ask in terms of high cost classes, with a particle engine as an example. I read somewhere that an instance of a class with a high cost to initialize, like a particle manager, should have its state variables altered at run time rather than reinitialize the particle manager with new data every time it is used in a diff...
I saw this in code and was wondering if there is any performance benefit to checking the item count prior to looping: if (SqlParams.Count > 0) foreach (var prm in SqlParams) cmd.Parameters.Add(prm); I always prefer to do a null check instead and let the foreach loop just hop out if there are 0 items. if (S...
It's a rather simple concept, and each vendor seems to have their own "Website" for their config. I am curious to find out a few things. In my linksys router, if I go to 192.168.1.1, it asks for a simple log in, followed by the status page. Here ports/passwords and all that can be completely changed. What's interesting...
I'm currently learning how to develop web apps with C#, ASP, .NET and MVC. I am enjoying the MVC paradigm a lot, but then thought about using this to develop desktop software with. I googled around, but found nothing using the MVC pattern to create desktop apps that connect to databases. So what software pattern do .ne...
To provide some context, I've seen some comments lately that equate inheriting behavior from a supertype, with inheriting a pure interface with no behavior. But there are pretty significant, and different, consequences to each. e.g. Here's a sample base class, and a "pure" interface (pseudocode): class FlyingBird { ...
I really enjoy working with C# however one of its biggest drawbacks is that it is kind of split-brained between MSFT .NET and Mono. In practice its not a big deal most of the time but it is one of those things that makes the language 'stink' a little. It would get a lot more uptake, I suspect, if one could answer "If I...
I tend to find that after I build an application, the logs emitted by it become near useless and completely unparseable, and has the problem of being really verbose, while not outputting important stuff. Example: Apr 9 21:49:58.648 [ DEBUG] - Read configuration successfully Apr 9 21:49:58.649 [ INFO] -...
I'm writing an enterprisey utility that collects exception information and writes to the Windows Event Log, sends an email, etc. This utility class will be used by all applications in the corporation: web, BizTalk, Windows Services, etc. Currently this class: holds state given to it via public properties calls out to ...
I have noticed that all the columns in a SQL Select Query should be in a aggregate function, because otherwise the output value for group would be arbitrary. This makes sense. But when the other columns are same in value, it doesn't matter which is returned. Is there a way to specify this or just use MAX() or MIN() on ...
I'm having trouble coming up with an approach that isn't n^2 for this problem. Here's a contrived, simplified version I've come up with: Let's say you're a company that needs 4 employees to launch in a new city, a manager, two salespeople, and a customer support rep, and you magically know how much impact every candida...
As title says it, i'm looking for a way to store many dictionaries (one per user) of type Dictionary<DateTime,enum> in a database (sql server 2012). Each dictionary has 366 items inside and it represents a calendar where each day has a certain "status", and preferably i don't want to store each item as a separate recor...
I've read quite a lot of posts lately about different branching strategies (e.g a lot of links from To branch or not to branch?), and while almost every article explains on how to do this or that strategy they rarely explain the why. Currently our team is investigating whether or not to switch to "feature branches". We...
Can customer take one of tasks during the planning meeting, which was already assigned to this team, and put it to another team? For example because a customer think that the other team will be faster in implementing it? Is it normal for some agile methodologies? If yes, could you, please, provide me with the source o...
Basically, what I would like to obtain is a way to iterate through ONE list, and call methods specific to the interface the objects in the collection implement. In my Java project, it would result in something like this: //GameComponent would be my empty abstract class HashSet<GameComponent> components = new HashSet<...
I just started to draw class diagram, I think it is based on 3-tie architecture. I have mobile application, servers, database, and web interface. But I do not know if it should put the server in? I just want to write a high-level one.
Given the following scenario A canned enterprise application that maintains its own connection pool A homegrown client application to the enterprise app. This app is built using Spring framework, with the DAO pattern While I may have a simplistic view of this, I think the following line of thinking is sound: Having ...
I've searched about this here and on StackOverflow and found some differences between the two. But I'm still not sure in what cases one would prefer a Singleton, and in what cases one would choose to use a static class. (In languages which don't support 'static classes', like Java, I'm obviously referring to classes co...
I am working on an ASP.NET application. One requirement by the users is they are capable of exporting to Excel of some UIs. I have worked on them using the Infragistics library, and I have supplied them with the exports they want. However, some of the UIs they see are so complex that it takes a great amount of time to ...
Update: I was wrong about the PyQt license. It isn't merely a GPL license. The PyQt authors include a special set of exceptions that allow users to release their own code under a different license, as long as it is one of the Open-Source licenses specifically listed in the PyQt GPL_EXCEPTION.TXT file. For the purpos...
What is the recommended approach for helper functions? I would like to choose one technique, and run with it to create my new "class". Here are the design options I have pondered: Option 1: Helper function in outer scope, invoke with context of instance function createPane (pane) { // logic to create pane var p...
This is a newbie question, but I couldn't find a newbie-proof enough answer on Google. What do people mean when they say 'state' - in programming in general, and in OO programming specifically? Also, what is mutable and immutable state - again, generally in programming and also specifically in OOP?
I have used WPF for an Enterprise solution (hundreds views heavily used Data inputs and validation) in MVP pattern (it was a clean solution usually small amount of code behind forms and main code was in pretension layer which we called it user interface process or UIP layer ) For the next small projects I used WPF wit...
Unicode seems that its becoming more and more ubiquitous these days if it's not already, but I have to wonder if there are any domains were Unicode isn't the best implementation choice. Are there any languages or scripts that Unicode will not work well or won't work at all? Are there any technical reasons to use a diff...
Unit tests should be isolated, automated ( ie we don't need to do any prior-configuration for all tests to run at the click of a button ) and consistent in their results. For these reasons we should stub any external dependencies ( ie databases, webservices etc ) used by unit under test UUT ( with integration tests UUT...
I'm not sure if I'm being clever or making things more difficult. I'm working within a custom MVC framework, and within some of my "views" which contain forms I'm preserving input and styling errors as follows: <form action="submit" method="POST"> <label for="name" class="italic">Name:</label> <input <?php if (in_array...
You task is to design a search algorithm that will find my secret number, which is between 0 and 2^64. If your test value is too low you can test again in 1 second. If your test value is too high you are not allowed to test again the next 300 seconds. Every second I will add 1 to or subtract 1 from the number. I will n...
I'm new to DDD and IOC/DI and I'm having some trouble figuring out how to design an entity that needs to use a state pattern to manage its status. As the transitions are somewhat complicated, I'm using a finite state machine (FSM) to handle the states (I'm using Stateless). To further complicate the situation, the FSM...
I understand that Singelton helps to instantiate only one class AT A TIME. I try to learn how to Design for Singleton function in java. I want to know it better to understand Kernel. So I try to do this following, but I like to know if it's the only way to come up with private constructor. public class Singleton { ...
In the 1970s, a man called Bill Gates developed an interpreter for BASIC: the Altair BASIC. Per my understanding, he was able to persuade the guy in charge of a microcomputer company to include the interpreter program on every microcomputer he sold, which I assume brought Gates and his crew some royalties. Apparently t...
I am in charge with updating a software product that is made up of two components the Controller process and the UI process. The Controller and the UI communicate via XML messages. Furthermore, the Controller is built on top of a shared library that implements a number of business flows. For builing the messages for Co...
I have a database table with 3 columns; id, question and answer. On the front-end, I have a PHP application that shows questions to the user. The application would then compare the user input with the answer on the database. Using only PHP, how do I loosely compare user's input with the record on the database and pass ...
There are situations where the deployed environment (development, test, or production, for example) might dictate the outcome of certain actions. For example, perhaps a successful "user registration" process will send a notification email to the new user. Environment-specific actions: Development: Do not actually se...
I have a problem that is more serious than it might seem. I've been programming for about three years , and I have learned and improved a lot , I read the code easily to others, understand the problems and transform them into code, I easily adapt to new technology and I love to learn how it all works . That's all fine ...
I was just working with a method of about 70 lines of code developed by others. It uses a very nice pattern structure, stuff like IOC container, but I wonder.. The method is too long? Is it a so long method still easily readable? The question could be finished, but now starts the premise from which my question has orig...
What's the difference between model for test and model for development? Is it that the model for test contains only what we should test? Do we use the same diagrams in model for test and model for development? For example, if we use sequence diagrams for generating test cases, these diagrams will not be used for coding...
I have joined writing middle-size multi-purpose database application as co-lead. It currently has about 150 tables (and growing) and overall functionality you can imagine as very small ERP. At many places in code, functionalities which would normally belong into procedures (I mean functions without return value) like D...
Most people here and on StackOverflow agree that Singletons are evil. The main explanation I've come across against the use of Singletons, is they fact that they provide a global point of access to an object. I admit to not understand why this is a bad thing. It's very convenient to be able to access an important and u...
When I'm coding something I know that there are many ways to see if my code is good or not. First is testing: I can do unit tests or even test the software by myself and see that it works or not. After getting it working, I can analyze the coupling of the code and so on to refactor and make it better. In that sense, I'...
Note: the following is C++03 code, but we expect a move to C++11 in the next two years, so we must keep that in mind. I'm writing a guideline (for newbies, among others) about how to write an abstract interface in C++. I've read both articles of Sutter on the subject, searched the internet for examples and answers, and...
One of my projects just changed the version number of a supporting third-party library. Specifically, we changed a J2EE app from JPA 1.x to JPA 2.0. Our CI system has had this change for a week and the tests are passing. In general, how can I do an effective code review and QA check when another developer changes the v...
I'm getting into the Repository pattern (which I love), and as I read up on it I see this UnitOfWork pattern in many articles. Before I knew anything about UnitOfWork I was just using my Repository pattern inside my service layer (business logic). This seems to work great so I'm wondering why having another layer (ie. ...
What kind of process or static analysis would catch the heart bleed bug other than human code reviews which we already know failed. The Fix Commit is here.