instruction
stringlengths
34
19.9k
I have Student and Group entities. Student can have many groups and Group can have many students too. so in database I should have middle class and change many-to-many relation to one-to-many and many-to-one. My question is how should I design class diagram in oop? If middle table does not have any extra field(just stu...
I have a set of classes that represent different objects (tables in a database): class ObjA: # some class specific attributes and methods def refresh(self): # implementation pass class ObjB: # some class specific attributes and methods def refresh(self): # implementation ...
I have two designs which achieve the same result. -------Design A MainClass has a List and two methods. The methods create an autonomous object and is added to the list. The reason for the superclass, B and C are similar and I will be adding more subclasses. Furthermore, I can take advantage of polymorphism later on....
I have a system with a structure like this: The ConcreteWriteable is caching the ReadOnlyWrapper. This is a similar system to what .Net's System.Array uses for its Array.AsReadOnly<T>(T[] array) method (ignoring for the moment that System.Array's AsReadOnly is static). However looking at the code for System.Array at r...
I was reading about copy constructors for structs and i found this example: #include <iostream> #include <string> using namespace std; struct SomeData { int * pd; string id; SomeData(SomeData & ref) { cout << "Copy Constructor called" << endl; pd = new int (*ref.pd); id = "Copy Cons...
I'm trying to make a service that's polymorphic based upon what mode is specified in the URL. If the char param in the route is set to 'p', I want to use a PresentMode service. If the char param is set to 'n', I want to use a NoteMode service. Each of these present the same interface, but I want to choose one at a time...
It is a Design Problem which I am listing out here. I have different set of business operations that are carried out for different business entities. Operations: Operation A Operation B Operation C For Example I have an Entity A. Entity A's data could be in parts, for example: Entity A's (Jan Data) Entity B's (Feb ...
When do you feel that you need a new class (maybe when you are developing or after development for refactoring purpose)? Maybe I can start from my existing variables and think how I can reorganize them into some classes! Please add more!
There are two ways to execute AsynTask, i.e., execute and executeOnExecutor. I already know that execute works serially and executeOnExecutor works in parallel. So my question is: Which one to use? Which one is better? Can someone help me understand which one to use in which situation?
We are developing a framework that has several layers and would be deployed in a multi-threaded environment. Each layer may have its own input/output data type. The top layer takes the input, performs some actions on the data and passes it to the next layer. Based on the output from next layer, the top layer would perf...
I really cannot decide what option is the best, I see plenty of down/upsides to both approaches and right now I'm undecided. For example; class DX11GBuffer { public: DX11GBuffer(ID3D11DevicePtr device, ID3D11DeviceContextPtr context, D3D11_TEXTURE2D_DESC backbufferTextureDesc); ~DX11GBuffer(); void BindFor...
I'm practicing around building e-commerce asp.net applications that allows for users to register to the site and their user credentials are stored in a MySQL database. In my sample project the registration asks for the users username, password, full name, phone #, email, home address (for shipping of products purposes)...
I am curious why exception handling is a topic often ignored in Scala. Is it the goal of the language (or the style) to not rely on exception handling except for external input/code? I was hoping the style guide had some discussion on exception checking/handling. Is there a good reference that I could consult to under...
I'm familiar with the notion in c++ of the rule of 3, however since the release of C++11 I've seen some sources suggesting it should be extended to a "rule of 5", I.e. the move constructor and move assignment operator should also be implemented whenever the others are. What is the rationale behind such a rule? My under...
I am still pretty new to programming, but my first app was recently approved and is now for sale on the App Store. My app uses Core Data and is written in Swift. After some initial difficulties, I decide to write the app without unit tests. Now I'd like to implement unit tests to prevent regression. My managed objects ...
I am having some problems trying to figure out when to use a factory or to wrapper class. This question is slightly geared towards C# I guess, so I'm not sure if this is the correct place to ask. Say there is a library that exposes an interface called IStackExchangeClient, and multiple differing implementations of that...
Given are two sorted arrays a, b of type T with size n and m. I am looking for an algorithm that merges the two arrays into a new array (of maximum size n+m). If you have a cheap comparison operation, this is pretty simple. Just take from the array with the lowest first element until one or both arrays are completely ...
In my school management system I have this partial class diagram: 1- In one use case student want to see his schedule of classes in week. this is what i suppose to do: get student object from session and call method getSchedule() on that and it will give me schedule(this method calls StudentCourse, Course for getting...
Recently ive been consumed by creating my own simple CPU architecture that at some point could be easily implemented in hardware (No FPGA, but actual Logic Gate circuits). Naturally to fulfill this requirement i went with a simple 4 Bit CPU, with a 4kB program space and 256 Byte RAM. It supports all the fundamental op...
I currently have one separate project for my models, and one separate project for a API application that consumes this model. The intention of the separation is to avoid any outgoing dependencies from the core model to consumers like the API project, enabling me to have a nice layered structure of responsibility. In th...
I'm currently revisiting some code I wrote in sass when I was learning it and I came upon a particular issue. I was able to write the code in 2 ways, with the first being the more readable code and the second being the shortest code when compiled to css. I was wondering whether it's a good thing to sacrifice some reada...
I have to implement the AI for Abalone game and I'm wondering what is the best way to represent the board logic using Java without wasting too much resources in all checks and updates routines involved. Is better use various lists? A matrix of Cell objects? Any suggestion?
With some platforms, like LinkedIn, you can see a list of all sessions where you are logged in, and you can even log them out on a distance. How would you implement something like that? I'm not talking about specific code, but more about general flow. I am using ASP.NET myself, but I think a general approach would be ...
The tutorials I find to setup OS-X for web developer programming (installing x-code ruby js cocoapods sql c asm etc) leave out if it should be done from an admin account, or standard (managed) user. Some methods I've seen used: Setup dev environment from admin account, then change admin to managed user. Or install dev ...
So OOP is about breaking down functionality, making each class responsible for one thing etc. But let's take the example where an object is using another object. First thing that comes to mind "composition, of course!". I have 2 questions: Question 1: Suppose you have a Shop that is loading products from a file using a...
I am a desktop developer moving to web development. The guys who I am working with use procedural PHP, and coming from an event driven, objectified perspective (using WPF and C#.Net) I am completely lost in what seems like the Wild West of development. Are there any language/framework combinations that allow some sembl...
I often wondered why C Language is taught as the basis of programming languages everywhere. There are a lot of modern languages like Java, Python etc. which makes the syntax and programming easier. Why are we still holding the C Language up in the front as the basics of programming languages?
Will it be difficult in developing a programming language which is much more closer to our language ? It was just to know the view of programmers across the globe towards the natural programming language.Thanks for giving me your views on this .
I have an algorithm problem. I'll simplify the issue, because most of what I'm dealing with has nothing to do with the algorithm I need. Basically, I have a list of objects that each have properties. Let's say for the sake of simplicity that this was a simple struct or another simple data type containing a string ID an...
I recently stumbled upon a special Sudoku variant and am now struggling to effectively solve it programatically. Consider the following initial 6x6 grid: The rules The red question mark is supposed to represent our secret digit. The secret digit behaves like a normal digit. That is, it has an actual value between 1 an...
Are there succesful ways (i.e. non spammed by 1000 bots per second!) to propose some user interaction on a website such as : Voting up / Voting down / Liking posts Posting comments but without account registration and without captcha ? I have read that filtering by IP is not relevant, for many reasons (people may ha...
When programming for android, whenever I use an AsyncTask the doInBackground method looks like this. protected String doInBackground(String... args) But when using the arguments anywhere in that block I can access them like a normal String array for example in my program @Override protected String doInBac...
We have a large project written in PHP. It almost exclusively uses imperative operations, as in example 1. Should we refactor our existing code to use functional operations? Do you think that the code in example 2 is easier to maintain? Example 1 - imperative $cookieString = ''; foreach($cookieArray as $cookieName ...
In my new project, I decided to try with TDD. And in very beginning I encountered a problem. First thing that I want to do in my application is to give ability to read data from data source. For this purpose, I want to use repository pattern. And now: If test are for real implementation of repository interface, I wil...
I am developing a small project to sell and I have used several Java libraries, mostly with LGPL or Apache 2. And I have one question, for example, I am using jasypt, wich is an Apache 2 license library, but this requires the commons collections library, also Apache 2. Do I need to put in my license form the common co...
I have recently joined a team in which the developers were able to work completely in live production to produce business intelligence products for customers. Recently, management, at the advice of SAP, have moved the team to a 3 stage environment Develop Test Production which require transports between each layer. ...
I am a beginner at programming; so far all the compilers I have used can check for errors, and can refer to the line with the error. Are there any compilers, maybe for a certain language, that do not do this? at least at the professional level? The error-checking is great.
I am looking at extending/modifying a web application licensed under AGPL for my own business. The program that I am modifying doesn't interact with the public, but with my employees who will be using the program. Specifically, the program manages our inventory, manufacturing, orders, etc. If I modify the source code ...
My question is related to MVC design pattern and Razor Syntax introduced by Microsoft. While learning MVC design pattern I was told that the idea is based upon a principle known as Separation of Concerns. But Razor Syntax allows us to use C# in Views directly. Isn't this intersection of concerns?
I built a Qt application. Am I allowed to LICENSE it under the MIT license? Qt is a cross-platform application and UI framework for developers using C++ or QML, a CSS & JavaScript like language. Qt Creator is the supporting Qt IDE. Qt Cloud Services provides connected application backend features to Qt applications. Q...
Many of the textbooks on the C programming language tell that C is a high-level programming language, but many of the tutors online say that C is also a middle-level programming language. Why is it like that?
I am developing some custom controls in an Object Oriented language (using Swift/Cocoa but this is a technology agnostic question). In particular, I have a horizontal and vertical set of buttons that behave very similarly except for the fact that one is oriented vertically and the other horizontally. My question: what ...
It is typical for Mac OS X apps to have preferences that apply seamlessly, and preferences dialogs don't have "OK" or "Apply" button. I want to implement this behavior in my project, but I can't decide when to apply/save changes made by user. It's quite clear that checkboxes and drop-downs can be saved immediately upo...
I have built an appointments system for various medical practices. Practice schedule appointments - I am looking to provide analysis on the amount of time that has been utilised by the practice. I can break up my requirements into lots of smaller queries in order to calculate the percentage of available time that has b...
From what I've read and implemented, DTO is the object that hold a subset of value from a Data model, in most cases these are immutable objects. What about the case where I need to pass either new value or changes back to the database? Should I work directly with the data model/actual entity from my DAL in my Presenta...
There are good annotated vocabulary in {a,i,my}spell dictionaries, giving the lexical class et all. I'm writing a program that needs a large vocabulary, but with a reduced scope, so I don't need all the information on the *spell dictionaries. Then, I'm reading this dictionary data, processing it and rewriting in my ow...
I've been using a tiny and neat caching library on my projects, but I realize that "Cache" is a very generic name and it's easy to get a collision when using it in large projects. Also, I would like to publish it in Github in order to share it with colleagues and make it easy for all of us to install using composer. Th...
I am learning test driven develeopment and read some books about TDD. I learned rules of unit testing. How can I write unit test, how can I select test method names, Act, Assert, Action and like this. In real word I developed applications that have layered architecture. Domain Layer, Data Layer, Service Layer, UI Laye...
I have only recently started to market myself as a 'programmer' rather than an analyst or something else entirely. In a recent search of freelance/part-time/contract work, I came across an ad for a contract "R Programmer". I was well qualified for the position and submitted my technical resume. I had an interview an...
We are discussing on building a web application where (as per clients requirement), there will be relatively large data (60,000 items) to be shown as tree view. Let's assume each item is string of 500 characters . My questions is about maintaining such data on client side. Basically this is an overkill to be used in as...
I was reading most common database design mistakes made by developer Q&A on stackoverflow. At first answer there was phrase about exclusive arc: An exclusive arc is a common mistake where a table is created with two or more foreign keys where one and only one of them can be non-null. Big mistake. For one thing it ...
I am fairly new to functional programming and C#/F#. What is unclear to me is: Can you do functional programming in C# and/or in F#? Or is it something like, you write some OO code in C#, and some FP code in F#, and use them together?
So far I have only done personal projects at home. I hope to get involved in some open source project some time next year. The languages I that have been using the most are C and C++. I have used both languages for over a year and I feel like I have become quite proficient with both of them, but I really don't know whi...
When creating AMD modules you can export whatever you like whether it be an object or a function. I vaguely recall reading a recommendation somewhere to export just one thing; the idea being "keep it small." Using this philosophy means that one might go as far as to export single functions. And when this is coupled w...
I am thinking about a way to create a flexible "settings class" in C#. The question is: How to provide a confortable way to provide default values to the settings. I want the programmer to access the default settings as easy as possible using intellisense. Therefore I encapsulated the default values in a subclass of th...
What would be the best practice to declare lambdas in Java8 code? How it was designed to be used? For example, let's say that we have a method that accept a Function. I want to provide function implementation that can be reusable. So I can do this: [A] Implement a Function interface: public class Foo implements Functio...
I (I am sure everyone else also) have always seen comparisons of some value to 999 or 9999 .... etc. for e.g.: in CSS z-index: 9999 or some times str.length < 99999 I wonder if there is some fact behind it or its a trend.
In a game I'm developing, the GUI thread is catching user actions, and the simulation thread is responsible of handling and responding to them. To minimize complexity and delay, I predefined all possible action types the user may trigger, and created an array of "opcodes". The GUI thread sets "happened" to the relevant...
It's drilled into the newbie Java programmers that Java (pre-Java 8) has no multiple class inheritance, and only multiple interface inheritance, because otherwise you run into diamond inheritance problem (Class A inherits from classes B and C, both of which implement method X. So which of those classes' implementation ...
Total no: of filters possible is M . User can select m filters where m <= M . A typical example is files from a folder , he could say modified between so and so date , start with so and so and so on. meets = [] for each in something: if user_filter1: if user_filter1_condition_met: meets.append(True...
I'm writing a Java desktop application that will be available to the public. It will contact backend APIs via HTTPS using Jersey client. I don't know anything about using certificates in desktop apps but from what I've found out so far I'll need to create an SSLContext that reads a public certificate from a KeyStore th...
I'm trying to implement a method of searching trough a large amount of 2D points for those that match a certain range. I'm thinking of creating HashMaps for <X, Point> and <Y, Point> but I'm wondering is HashMap good for doing this, because I will be taking points in a range, based on values from x_min to x_max and y_m...
I have a compiler for a programming language that targets JavaScript. That language needs some global functions such as: alloc, memcpy, write and so on. My question is: where should I position those functions? I have pretty much 2 options: 1: inside a self-contained object, runtime. Compiled functions would need to rec...
I am using Cassandra for a data intensive app. With relatively little operations and deployment experience, the expertise I am looking for is someone that can read the example below and decide whether I am overlooking simpler solutions, or if the resources needed make this problem expensive or intractable. ~A million...
I am writing a simple framework that I want to open source just for experience (and fun!). However, it has some cool ideas that could make it grow to a larger project and I want to be ready if that ever happens. I highly doubt that that will happen, but I want to use this as a learning experience on how to properly run...
I wanted to know if there is an equivalent of the C# generic delegates in Scala. The reference website is: http://msdn.microsoft.com/en-us/library/dd233060.aspx I'm trying to make a complete comparison between C# and Scala, about (co)(contra)(in)variance.
I've recently started to do some more complicated programming with network-related work on iOS with Swift. This introduced a lot of asynchronous code not only in networking but also some exchange of information between view controllers. Anyway, my question is simple, and can be quite general. As far as I know, there ...
I don't know how to refactor a piece of code that differs from other in the number of conditions checked on an if clause. Let me show you a real world example I'm facing right now. The only difference between the two methods is that on the inner elseif, it checks an additional condition on the new parameter. Method 1: ...
I would like to use some code that was released under GPLv2 in my project. I released my project with the GPLv3 license. Can I do this, or do I have to downgrade to GPLv2?
I'm currently trying to add TDD on my workflow. I fail to create tests where I can easily test a library that requires remote connections. More precise, my program uses snmp4j library. Currently I'm working with 1 release behind due to I don't know what's the impact of the new API release on my code. So I read that imp...
What is the recommended etiquette when it comes to EINTR in libraries? I'm currently writing a function that does some file system tasks with the POSIX API, but a lot of the calls I use can potentially return EINTR. Additionally, the function can block under some circumstances. (For those interested, it implements a ...
I have been passing callbacks or just triggering the functions from other function in my programs to make things happen once tasks complete. When something finishes, I trigger the function directly: var ground = 'clean'; function shovelSnow(){ console.log("Cleaning Snow"); ground = 'clean'; } function makeItS...
I have a asp.net web forms page where admins can search by user last name and then select them and approve or deny their access to the site. When users request access, an email is sent out informing admins. I want to be able to send a link that populates the page with that users info for easier approval. How would I ap...
I am developing services using Asp.Net Web Api. I am debating on design of our controllers. We have this common scenario where user will be presented with bunch of search field, once he enters the search criteria we will show summary of records (not the complete details), user will select one summary record and can go ...
I'm not sure how possible it even is but as a programmer I have a sense of risk involved when I'm making changes to a code base. I've never seen a tool which basically tells me, as I'm coding, how far reaching my changes potentially are. Examples off the top of my head (which are probably debatable but this is just to ...
I wrote a multi-threaded program that randomly generates strings, and after generating, checks to see if the string contains a certain value. Namely, StringGenerator and StringChecker. What I'm trying to figure out is how many StringGenerator threads I would need in order to keep StringChecker busy. All StringGenerator...
I'm trying to understand in a general sense how L1/L2 (and now L3 caches) are updated and how the updates are propagated in a multi-core x86/x86-64 CPU. Assuming a 4 core CPU and 2 pairs of L1/L2 caches, where pairs of cores share a common L1/L2 pair and there's an interconnect between the 2 L1/L2 pairs. And the cache ...
I am writing a program which is a similar to Ruby's Active Record Migrations, in which that every migration has both an "Up" and "Down" in terms of creating a change to the database, "Up" meaning bring the database forward in time, and "Down" reversing that change. My program has two main functions to achieve its use-c...
I want to add values to a HashMap, which would be used by methods in the same class. I have two solutions: Adding all the values with static When the first method is called, add the values Solution #1: private static Map<Character, String> codes = new HashMap<>(); static { codes.put('A', ".-"); codes.put('B'...
Say we have our route finding algorithm: def myHeuristicTSP(graph): /*implementation*/ return route Now we want to unit test this: class TestMyHeuristicTSP: def testNullGraphRaiseValueError(self): self.assertRaises(ValueError, myHueristicTSP(None)) def testSimpleTwoNodeGraphReturnsRoute: ...
When designing and implenting an object-oriented programming language, at some point one must make a choice about implementing fundamental types (like int, float, double or equivalents) as classes or something else. Clearly, languages in the C family have a tendency not to define them as classes (Java has special primi...
I'm trying to understand some of the nuances of inheritance but I can't find an answer to this question. Consider the following: class SuperClass { method foo { print "in SuperClass.foo" } method bar { print "in SuperClass.bar" foo(); } } class SubClass inherits SuperClass { ...
I use composer for PHP dependencies. I was under the impression that for front end dependencies I should use Bower. So, I installed Bower and loaded my FE dependencies (Bootstrap, jQuery) using that. I then manually symlink to the libraries as follows: mypc:/var/www/myproject/public/js$ ls -l total 8 lrwxrwxrwx 1 tom t...
I have a fairly substantial Python project that I have developed as an educational endeavor. The version of the code that shall be given to students has exercises throughout, in the form of code that I have deleted and replaced with an exception. To be specific: def mk_eq_term(i): # raise ExerciseError("B...
In an example: var assets = "images/" var sounds = assets+"sounds/" Is it more conventional to put the slash on the back of a file path? var assets = "/images" var sounds = assets+"/sounds" Is there another method that is a good common practice?
In projects which need heavy SDK usage, like Android and iOS development, I want the methods/functions I write to be obvious and since the whole framework is written with lower case method names I would like to have my method names start with upper case. However is this a good approach if there are going to be other pr...
I'm using Bower whereby I run bower install and it downloads dependency files to /bower_components directory. Then, I create symlinks from my /public/.. directories to the dist files: mypc:/var/www/myproject/public/js$ ls -l total 8 lrwxrwxrwx 1 tom tom 67 Dec 23 07:29 bootstrap.min.js -> /var/www/myproject/bower_com...
I'm having trouble deciding the best way to handle splitting up if block checks for different architectures. I may be handling the scenario completely wrong, so let me know if that is the case, or if this is a duplicate. As a simple example, suppose we have two parameters to consider for a web script: member status (n...
Situation: We have a web application running on a server. This application needs to fetch data from some other PC(Clients), which are on a different network. On the clients' pc there are WCF hosted in Windows Services using its their local Sql db. i want to make duplex communication between server and clients for share...
In C#, when a user creates an List<byte> and adds bytes to it, there is a chance it runs out of space and needs to allocate more space. It allocates double (or some other multiplier) the size of the previous array, copies the bytes over and discards the reference to the old array. I know that the list grows exponential...
So for MST there are 2 possible definitions in an undirected graph. Keep in mind that in an undirected graph the MST algorithm always has n - 1 edges and no cycles. In an undirected graph, it doesn't matter which definition you use, since both are correct, however inside a directed graph thats not the case anymore. Def...
I've searched around for a long time now and haven't come up with any official reason why scala doesn't support multiple inheritance. I know traits solve a lot of things, but the developers of C# for example give an explicit reason why not to implement it (link here). Any pointers?
I am creating a DLL that I want to distribute to public to use it the way they want. This DLL contains common utility functions. People can use it on any operating system and with any language or framework. So, I want to ask that the DLL created using .NET 3.5 or above is accessible from other languages, operating syst...
Let's say a client makes a GET call to the server to get all the followers of some user. now the client shows a list of all the followers but the only data the list needs is: {"username" : "user", "thumbUrl" : "http:/www.example.com/photo/1", "age" : 78} now the user can click on one of the followers and he can see m...
There are tons of "theoretical" arguments for why functional programming is a Good idea (too many for that to have stayed as an open question, and correctly so). However, most of them are arguments either made from theory ("elegance", etc...), or, aimed at developers. The problem is, most of them are entirely useless w...
I have a 3-tiered web application with a web view layer, a business logic layer, and a database persistence layer. I am adding a feature that populates a history table with records if and only if the element being saved has changed (it compares the previous and current records and saves the history records if anything ...
I have a table that has around 60 rows and 20 columns. Each cell has a directive with an isolated scope. I use 2 nested ng-repeats to generate the table (one for rows and one for columns), but I'm wondering how angular handles scope when a digest cycle causes a re-generation of the directives in the ng-repeats? Does ...
I've heard people talking about "eventual consistency" (for example in this question and this answer). What is "eventual consistency"? How does it compare to "transactional consistency"? When does it happen? What sort of impact does eventual consistency have on the design of systems which are affected by it? How can it...
I've heard people talk about business logic a lot at work, and online, and I've read several questions on this site about it, but the term still doesn't make a lot of sense to me. For example, here are some (paraphrased) statements I often see: "The business logic is the part of your program that encodes the actual bu...
In my short time programming, it has been trivial to compile any of my C++, Java, etc. for either a 32 or 64 bit machine so long as I have the full source for the program. But a lot of software is not released 64bit. Most annoyingly, there isn't yet a 64bit release of the Unity engine. What makes it difficult to compil...