instruction
stringlengths
34
36.1k
I am making an mvvm application for the uwp platform and I am looking for advice on the following matter. Take for example the windows 10 e-mail application, which when full screen displays both the e-mail list and e-mail content in one page, while in smaller form factors the content is displayed in separate pages. Wha...
I have an ASP.NET MVC4 web application, with EntityFramework for data access. In the application I have two repositories as follow (this is only an example not my real code): public class CustomerRepository { ICustomerContext _db; public CustomerRepository(ICustomerContext db) { _db = db; ...
A (relatively) simple CRUD application on which I work has a lookup table which holds key-value pairs, some of which have child key-value pairs. These are used mainly in drop-down lists on the application front end. Currently there is a RowStatus field to specify a key-value pair is active/inactive and is not to be inc...
I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anaemic. It's just a repository of getters and setters, and I want to refactor it. There is a thin line between Rich Model and God Class. I'm afraid to refactor my anaemic model into a god class. I want some opinio...
Since the purity of an input parameter is an unknown until runtime, is a function immediately considered impure if it takes a function as an input parameter? Related: if a function applies a pure function that is defined outside of the function, but is not passed in as a parameter, is it still pure if it fulfills the c...
I've seen some snippets of code do the following: CalculateSum mySum = new CalculateSum(); { mySum.add(50); }; while other developers do it this way (without the enclosing braces: CalculateSum mySum = new CalculateSum(); mySum.add(50); I understand that the first method ensures that the object is disposed of as so...
So, very often in your code you have statements/algorithms like this one: if (!myCollection.contains(unit)) throw new IllegalArgumentException(s"$unit is not available") The issue which I have with this approach that it clutters you source-code - this is especially true if you need extensive checks. I was thinking i...
Must all the controllers, models and views be placed in the private folders? If so, what are the roles of the public folder? What are the correct terminologies for such roles in computer science? How does the GUI relate with such concepts? Otherwise, does the controllers and/or views have to be distributed across the p...
I am implementing a programming language, for fun, in C. I have most of the parsing code done and also the AST ready. I once did write a runtime for this language some time ago, but I had some trouble with the garbage collector. I then realized i needed to study a little more and that my previous AST walker implementat...
I know this is a hot debate and the opinions tend to change over time as to the best approach practice. I used to use exclusively field injection for my classes, until I started reading up on different blogs (exs: petrikainulainen and schauderhaft and fowler) about the benefits of constructor injection. I have since s...
I'm coming from a J2EE development environment, and by there, I used a Servlet context to hold all the website meta data (title, description ...) for the whole application (some kind of a session for the application when running) as my meta data are retrieved from Database. In PHP, the context is different, we don't de...
Using models is one the best facts in Laravel, but when using a model, it is not like my "native" environment (J2EE, models declare all DB table colums), it has three variable, and which of them is "fillable". When seeing the tutorials online, the fillable hold some specific data like in a table : Table : Users Fields ...
Hypothetical problem, inspired by How to query Aggregate Root to react to event from other AR How should an event sourced application handle data, where the license to that data can expire? Example: the model includes sensitive billing information; when an account is closed, the billing information for that client nee...
I could imagine the below code being somewhat useful. Is there a reason this pattern hasn't made it into programming languages? To be clear the string was just what I chose as an example you could substitute near any type you like for the input and my question would still apply. public string switch findLastName(string...
I'm a one-man band and I have a contract with a client to develop and maintain a web-based system that is relied upon. This is the first project of this size and type that I have done for anyone else so I'm still finding my feet a bit in that respect and I'm not sure on any standard practices. The current situation is ...
I am working on a small multi player game for my final year project and currently working on the server. It's a Tank Battle game and have two main entities which I will use on the server side which are Player (Player details like username, password, currentTank, statistics) Tank (Details of a tank like velocity, rotat...
I was working on my own parser generator tool in Clojure and then I realised I want to test it with some real programming languages. I can find a lot of existing language grammars only in antlr v4 format. That means if I can automatically translate antlr grammars to my own format, I can get them all. Is that a reasonab...
I have an object 'connection' which holds the path/credentials to a SQL DB. When calling methods; we usually do this: Connection con = new Connection(); GetSalesData(con); public static void (Connection con) { // Run code } As I understand, we just created two instance of connection, so that means two memory al...
I have a class Song, which has the following public methods: String getSong(); void setSong(String); int getId(); void setId(int); Now I have two different ways I might want to store these songs in a database: just two columns; one for ID, one for the whole text of the song three columns; one for ID, one for line num...
Wiki: A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is ...
Getters and setters are everywhere in Java, but they are managed in a horribly outdated way. Simply put: Why doesn't a newer version of Java enable a simpler syntax for managing it? Even if this syntax is converted to the old one by the compiler for compatibility, at least it would be good to let people write code with...
Formatting with Indentations, White spaces, and New Lines obviously fit into the coding style category. if (a == b) { foo(); } // vs if (a == b) { foo(); } On the other hand, something that changes the run time of a program is no longer a matter of coding style, and becomes a matter of algorithm. for (var i ...
function haha($lol) { if($lol) { echo "plus"; } else { echo "minus"; } } haha(-1) echoes plus. Is it because PHP uses twos complement? Google search wasn't really helpful.
I am currently building an application with a layered architecture in C. Currently, I have built and tested the bottom layer, which is a networking module, providing functionality such as connecting/disconnecting, sending messages, etc. On top of it, I am building another layer, that implements a communication protocol...
I just recently sent off a pull request to a small but well-known open source project. This pull request added a new feature, as well as unit tests (and improvements to the existing tests). However, the author is not accepting pull requests for this project...but that wasn't made clear until after I had already put i...
This is not a question, asking for a (single) tool, although to answer my question, of course tools are involved. The focus of this question is, asking for advice in which direction to head for. I have a JAVA-background, so in order to generate any document, Jasper Reports are a good starting point. Coming to Python, I...
I'm currently implementing functionality in Symfony (PHP - not that it should make any difference which language I'm using) where I have about four controllers that do almost exactly the same thing. The only difference between them is that they use different entity objects and form objects. I've already refactored all...
My node.js app has to deal with (sometimes large; a few MB) tables of numerical data. I'm about to use JavaScript's native binary objects for this purpose (i.e. ArrayBuffer and friends), because they're fast and well-supported by fantastic libraries like scijs-ndarray. I'm wondering now how to store this data, given th...
How should a product owner in scrum deal with very detailed questions from the team regarding the features they are implementing that he cannot instantly answer himself? When it would clearly be the faster solution for the developer to directly talk to the customer himself? I wonder if direct communication between the ...
Typically in a C# program, the entry point is in Program.cs. However, if you are creating a rather generic class library, with no Main() method, such as TCPClient.dll what is the appropriate base class name? (cannot be TCPClient as that is the namespace).
I would like to keep two Git repositories updated. First one, is GitHub open source project that gets updated frequently. Second one is a private held Git Repo located other than GitHub. This one would be modified code for the project requirements. Occasionally would to update the second repo with first open source pr...
The problem is that since you can use std:bind in a loop with an arbitrary number of iterations, the storage cannot be inline. It doesn't appear to be on the heap, since it doesn't appear to generate memory leaks. It seems, then, that it must be on the stack - SOME stack. I have an application which could easily do ...
I want to read a file into a collection of objects. The data (it's a Leica PTX file if you're curious) is formatted as follows: 640 [begin item #1: number of columns] 480 [number of rows] 0 0 0 [position information: 3x3 matrix] 0 0 0 [position ctd] 0 0 0 [position ctd] 1 0 0 0 [calibration information: 3x4 matrix] 0 1...
Me and my co-workers are having a bit of a discussion about one of the code analysis issues thrown by visual studio: CA1822 Mark members as static The 'this' parameter (or 'Me' in Visual Basic) of 'UnitTest.CreateSimulation()' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in ...
Suppose you have project A and project B, where project B depends on project A - let's say A is a library. And project A and project B live in separate version control repositories - either because project A was created by a third party, or because you just decided to organise your repositories that way. You want to ma...
I have a java class hierarchy that are formed by an Abstract class and N extensions of it. In the abstract class I have a method that is annotated with a @Remove annotation. While we won't get any exceptions of won't fail fast if this annotation is removed, we may get out of memory exceptions, so I would like to be sur...
Branches in git repos or similar are practically always derived from the same code base; after all, they're usually merged back in to master later. But, if you wanted your open source project on GitHub to have a website, you could use GitHub Pages, which lets you publish a site in a repo on a branch named gh-pages. Un...
I have a service that does fairly complicated business logic when it receives a request. I have most the functionality isolated into private methods which dive a couple levels down from the method that receives the request. Basically receive request -> private method for subprocessing -> private method for processing ...
A common feature we have is a report be available available in multiple formats. For example, a pricing report will be available as an Excel spreadsheet for the marketing team to be able to tweak the numbers, as a PDF report to look nice for external customers, and as ASCII text for emailing/SMS-ing out the sales staff...
I'm currently refreshing my Java knowledge and came across a question I couldn't answer yet: How does the Java compiler know where the (possibly custom) packages are located on disk? I'd assume that using built-in libraries it looks up the java library folder - but how does it find the custom ones? Here's the file's l...
Following this description of the Repository Pattern, we have three main concerns that need their own classes: The "Repository," which takes and returns Domain Models. The "Gateway," which takes data from the Domain Model and returns some sort of generic data The "Factory," which takes the "generic" data from the Gate...
What is the time complexity of the following piece of code in worst case? s = 0; for( i = 1; i <= n; ++i ) { for( j = 1; j <= i * i; j++ ) { for( k = 1; k <= j and j % i == 0; k++ ) s++; } } Each loop depend on the outer loop variable. How should I proceed in such a case? The innermost loop...
I want to subclass a 3rd party class, in order to make it thread-safe. I have a good idea of how to implement this, but there is a problem: the superclass has a property, which affects the behaviour of one of its methods. If one thread sets the property, it will interfere with the other threads when they call the metho...
I am studying "Threads" part with a textbook, Operating system concepts written by Abraham Silberschatz, Peter, Greg. First, I'm going to say something in the textbook related to my question, and then to ask the question. If someone already knows the following theory, skip to my question, please. The book defined para...
I recently downloaded VS 2015 and when writing an event handler, it auto completes a generic method for you, but it does so differently that what I learned/used. This is how I would normally write an event handler Foo.SomeEvent += new SomeEventHandler(SomeEvent); But VS2015 auto completes a method stub like this Foo.S...
I'm a software developer on a fairly large agile team (we have eight developers actively making changes to a single code repository). Every two weeks, we push a new version of our software to production. Here's our current workflow: When starting a new task, developers create a "feature branch" off of the main devel...
It's common to implement binary search trees with an internal Node class public class BinarySearchTree<TKey, TVal> { class Node { public readonly TKey Key; public readonly TVal Val; public Node Left, Right; public Node(TKey key, TVal val, Node left = null, Node right = null) ...
I'm developing a Content Management System (CMS) and I would like to include a "Save Changes" button. I mean: a user performs several changes in the database, but those changes are still not available. Just when the user presses the "Save Changes" button, those changes are "visible" for the website. I have thinking in ...
I'm experienced wed developer doing stuff for web for a several years. But now my customer need to build crossplatform ETL tool which he want to ship to his clients. And will be much easier if it will be desktop application. However I don't have good expertize in this field and in general don't feel great about desktop...
I have a collection of objects, and for each of them I need to know if a specific condition has been met. That is a ternary condition, it could be not yet tested, tested and failed, or tested and passed. Currently I have a map where the objects are keys, and the values are Booleans. The value is null until tested, and ...
I'm currently writing a library that abstracts 3D rendering and uses SharpDX and OpenTK as graphics libraries. The problem is that OpenTK and SharpDX have their own implementations of Vector2, Matrix, Quaternion and so on. I came up with 3 possible ways to deal with this. My API has to have function overloads for bot...
I have been assigned the task of automating entering of supplier prices and inventory based on our master google sheet. I have limited programming knowledge, but so far I have made code that can create an order sheet and send it via E-mail. The problem I'm facing now is that the prices are based on pdf/xlsx files we r...
I have a solution with many components with different deploy iter: WebAPI backend (on IIS) AngularJS frontend (on IIS) A process manager (as Windows service) A projection engine (as Windows service) A command handler (as Windows service) I develop all of this things. At the end of the day when something valuable is r...
You are building a system that keeps track of Companies. Those companies have Contacts. Those contacts are often specialists that only answer certain types of questions, such as Billing/Payment, Sales, Ordering, and Customer Support. Using Domain Driven Design and an Onion Architecture, I've modeled this with the foll...
I have been getting my head around monads in functional programming and seem to see some commonality between Perl's default variable $_ and FP monads. Is this true? Are there similarities, if not why not - perhaps this'll allow me to grok monads once and for all by understanding why the use of $_ is not monad like! My...
I see many REST API examples with URIs like http://<whatever>/widgets or http://<whatever>/widget/123, for a specific thing. For most things I would just stick with the front slash, but when requesting a specific id I'd rather use a colon, like http://<whatever>/widget:123. According to what I found here about best pr...
I have a class called BagItem and another class called EquipmentItem both classes are exact the same in methods, etc, with the exception of 1 property. BagItem have: public InventoryBagType BagType { get; private set; } EquipmentItem have: public InventoryEquipmentType EquipmentType { get; private set; } I guess I sh...
I have no experience in software licensing so far. I am releasing my first application but I am not familiar with any licenses. Most of the the summeries found that I can understand (http://opensource.org/licenses/category) are open source but I want my application to stay closed-source. I am a little lost among all th...
In java8, we are using interface.super. Considering the below points There are 2 interfaces but none of the interfaces inherit to another. There is implementation class which is inheriting both of those 2 interfaces. Each interface has a default method but the name is same for both of those methods. Now in this scen...
Can you think of any specific reason why deletion is usually significantly harder to implement than insertion for many (most?) data structures? Quick example: linked lists. Insertion is trivial, but deletion has a few special cases that make it significantly harder. Self-balancing binary search trees such as AVL and Re...
I am reading about SOLID principles. In Ruby tutorials and code samples, I often see subclass extensions like: class House attr_reader :items end class Room < House attr_reader :chair end p House.chair = 'baroque_style'# => NoMethodError Of course the examples are useful to show how easily classes are manipulate...
I have an HTTP serving an API which works either anonymously or with a secret key in a header, like so: GET /profile?authenticationKey Authorization: 1234567890 I want to reject any request coming in over HTTP that uses an Authorization header, since those headers would come across in plain text. But I'm not sure what...
I have a userspace application which interacts with a kernel-space driver in a Linux environment. The driver, in this case, is an LED driver. In typical *nix fashion, the driver exposes a file in /sys/class/leds/actled1:green/ called value. When the value of value exceeds a threshold, the LED turns on. So, my question ...
I'm creating a game world that consists of a 16 x 16 x 16 rubix cube (pictured), where the individual cubes are floating in space. The cubes continuously move along a single set path that links up with itself at the end. It might be helpful to think of them as traversing a 3D maze. Are there any algorithms or solution...
To keep it simpler for any client of my class, I have put a sequence of private method calls within one public method. The client then calls this method and all the methods within run to complete the action. E.g: public void DoRejection(string comments, string rejectionType) { GetPartstoReject(); U...
When defining methods in a class we do have an argument for the object on which the method is invoked i.e self. Say I have a class Foo, and an instance of it: class Foo: def m(self): pass foo = Foo() and we do something like this: foo_m = foo.m and then try calling foo_m with the same parameters the way wo...
For example, which of the following is correct ? // Return hello -- or -- // Returns hello function greeting() { return "Hello"; } I personally never conjugate them but I am wondering how right or wrong this does sounds to a native english speaker. I have been unable to find a real recommendation about it. An...
My co-worker and I discussing about the code readability on simple loops. Suppose a method takes an integer parameter and does some operation on the elements of an array depending on the parameter. e.g For the sake of simplicity, assume array bounds are negligible and there is no error generated by the codes I presente...
Spoiler alert! This question (and, possibly, answers) could contain spoilers regarding "Halt and Catch Fire" TV series. Background I'm a web deleloper and do not have a CS degreee, so my understanding about hardware is at How Do Computers Work? level. Question context Here's a dialog from episode 102 between a hacker (...
I have an AngularJS-based single-page app that allows the user to operate multiple items at the same time. I decided to use a multi-tab UI implemented in custom code. However, the user begin to ask for more and more tab management features like rearranging, going back to the last tab after closing, etc. and it feels li...
I have a skeletal implementation, as in Item 18 from Effective Java (extended discussion here). It is an abstract class that provides 2 public methods methodA() and methodB() that call subclasses methods to "fill the gaps" that I can't define in an abstracted manner. I developed it first by creating a concrete class an...
I've read this article: How to Write an Equality Method in Java. Basically, it provides a solution for an equals() method that supports inheritance: Point2D twoD = new Point2D(10, 20); Point3D threeD = new Point3D(10, 20, 50); twoD.equals(threeD); // true threeD.equals(twoD); // true But is it a good idea? these two...
In a current project of mine, I have decided to not put any significant amount of code in __init__.py files, simply because I don't like them. In my head, an __init__.py file is just there to inform Python that the folder is a module. I keep forgetting that they might contain lots of code just like any other Python mod...
My question is focused on design, and the code included in this question is meant to clarify the problem I'm experiencing. I'm interested in conceptual level answers and not code in order to answer my question. Background: When programming bare-metal systems, one often has to manipulate bits in memory-mapped register ...
I want to model an asynchronous request-response message exchange in UML. The request is sent from a client to a server. The server responses asynchronously. This can be modelled in a component model in two ways: Option 1 Request and response are two different interfaces with one method each. The server provides the ...
I'm trying to find the simplest way to model user-defined conditional statements without resorting to text parsing. This is fairly easy when there is only one condition in the statement because you can split that into an operand, a comparison operator, and a value to compare with. Just store those three and you can let...
nowadays, I am studying OS. In Communication in Client-Server Systems chapter, I've heard that using process-id instead of port-number has problems. But I don't understand why it does. I think using ip+pid is possible because each process has their own process-id (pid). Is my thought wrong?
I am transforming my Meteor collection to a class I've created: People = new Mongo.Collection('people', { transform: function(doc) { return new Person(doc); } }); Person has a bunch of methods, some of which control getting the data: var john = People.findOne({ name: 'John' }); john.getFullName(); I also have...
The plus sign + is used for addition and for string concatenation, but its companion: the minus sign, -, is generally not seen for trimming of strings or some other case other than subtraction. What could be the reason or limitations for that? Consider the following example in JavaScript: var a = "abcdefg"; var b = "ef...
JsonLogic is a data format (built on top of JSON) for storing and sharing rules between front-end and back-end code. It's essential that the same rule returns the same result whether executed by the JavaScript client or the PHP client. Currently the JavaScript client has tests in QUnit, and the PHP client has tests in...
I've read the operating system concepts 8th edition written by abraham silberschatz. However, I don't understand Pthread Scheduling. Thread-library schedules user-level-threads on LWP(Lightweight Process). This is Process-Contention Scope(PCS) because contention occurs between threads belonging to the same process. ...
I'm kind of in an impasse here. Lets say I have module A which exposes some methods returning objets and module B that uses said methods from Module A. Module A will have situations when it will have to return Nothing. The problem is: Of course I don't want to return Nothing. Many, many books, top-coders and heuristics...
Does a programmer need to have a deep understanding of digital electronics. Theoretical v/s practical. As what they teach us at college is pretty basic? If yes, then do all kinds of programmers (software developers/web developers/app developers) need it (deep understanding), should a security enthusiast (hacker) have ...
As far as I understand, a planning poker session usually is started by picking one item and assigning it a value (say, 1). This item will then serve as a reference for the rest of the session. From then on, all values will be relative to the first one. Question 1: There seems to be no frame of reference to compare this...
We are in a situation where the customer has requested an urgent deployment of the current features we are working on. These features are being developed in a mercurial branch named 'sprint 1' for arguments sake. We also need to start working on the next sprint whilst the customer undertakes UAT. If they report any is...
Some scenarios: If I have a project that uses source code from a GPL 2 licensed project, and another set of source code from an MIT licensed project, what do I license my whole project as? What if I have a project with multiple modules where one module uses source code from a GPL2 project and another uses source code ...
In recent weeks I became very concerned that the way I've been working with database connections for the past years, is simply wrong. I exclusively create a new connection for each database operation I have to perform. only in the more complex programs, I would stack several tasks (Sql commands) in the background and t...
I have seen the term "vanilla version" used seeral times. For example, I have seen the term on the Lasagna-users google group, where a user mentions the term: vanilla CNN package. So, when is a software called a vanilla version, and what should it have for it to be called it (or distinguish it from being a vanilla ve...
For learning purpose I want to create an app. So I thought I will do something real easy to learn a lot about object oriented programming and modelling. After some thinking I had the idea to do a simple Sport-Ranking app. I thought this is very simple and I could build it up further and further. So first, this is why ...
Consider the following association between the 2 classes . Here the association means, In the class Log I have an array of Traces. and in class Trace there is an object of Log. Here I have a problem in implementation these 2 classes now. If I want to make Log instance, I need an array of Trace and when I go to make an ...
I work on an application where we have the potential to attempt a file save in the top-level exception handler. The intention would be save a file which can then be sent into the support team, validated for corruption, and restored as far as possible. (We have a small enough customer base to work like this.) Is there a...
I've been working as a programmer on a project designed for generic software for gas stations (to be redistributed for many customers) for 18 months. The project is big. Today we have around 150 tables. We haven't used a specifc approuch, it was not well managed. The person table has today around 70 columns, but 15 mon...
I'm doing a compiler, and I'm using the System.out.println(); to print assembly; And the code get bigger, and more complicate to understand. I want to know whats is the difference of efficiency between this and if I should or no: System.out.println("iload"); Or: private void printAssemblyCode(String code) { System...
How are comments generally treated in programming languages and markup? I am writing a parser for some custom markup language and want to follow the principle of least surprise, so I'm trying to determine the general convention. For example, should a comment embedded within a token 'interfere' with the token or not? Ge...
I'm designing a Rest API for our web application. There's one idea that came to my mind today and I haven't found in recent searches: a "hello" resource, where clients are supposed to connect as the first step; it should be like the "entrance" to the whole service. The main reason is to have a defined point where I can...
In our codebase for a sophisticated system controlling many aspects of businesses, we have a certain unwritten law to not fudge around in code with complicated SQL, instead writing it into a function in the entity's class to centralize the database access, and this great pattern turned into pages and pages of class Car...
this is a problem I've been struggling a bit with. I often get brought along to join projects to help out with development. The problem is, a lot of times I'm assigned to fix bugs, implement new features, etc but I find myself lost in a large code base. I don't know which file is doing what; which functions are being c...
I'm trying to install numpy using this. This link opens with these instructions: These instructions describe how to build NumPy and SciPy libraries from source. If you just want to use NumPy or SciPy, install pre-built binaries as described in Installing the SciPy Stack. If I'm not wrong, to "build" generally means t...
Which is conventional? For example, this is in the constructor: public class Foo { ... public Foo(...) { // http requests } ... } and this is in the static method: public class Foo { ... public Foo(...) { ... } public static Foo get(...) { // http requests return Fo...
A logical error, contrary to a fatal runtime error, is a run time error which doesn't fatally terminate a program, but does something not intended. Is a logical error necessarily caused by the line of code for the earliest state which is wrong? Or can a logical error be caused by a line of code before the line for the ...