instruction stringlengths 34 19.9k |
|---|
I am wondering how are you guys handling an optional class properties.
Let's say I have a product that can bud doesn't have to have a color property. Is that really the best way of doing that? Should I use null object pattern? Should I use strategy pattern maybe? Should I maybe use a decorator pattern here so I'll have... |
Something really bothers me about the way authorization tends to be done with roles in ASP.NET MVC.
The way it is normally done is that you have a Users table and a Roles table. A User can have many Roles.
Then you decorate your controllers/actions with an authorize attribute saying which roles you want to allow access... |
I was wondering about the following implementation of
public void update(Observable obs, Object arg)
while I want to send to all of my observer and update using notifyObserver() I and passing a references to this the observer can use the getters from the subject to pull the information he wants.
What is the arg argum... |
Consider this screenshot from our development repository:
We are relatively new to git, so things are still somewhat confusing. The question at hand: If you take a look at the commits by me at the very top; are confusing to us. Why do I need to merge something if I didn't even branch anything?
I commited the adjust bu... |
I am running two separate programs which are similar enough that they share a lot of code. I run these programs often and after I evaluate the output. This is a very fluid process and everytime is different from the last time.
Currently I write a script named something like: "temp_evaluate_program_A" and then I will co... |
My employer has been moving from traditional waterfall projects to a modified version of agile. Work is broken into stories, which are estimated and sequenced into two-week long iterations. Each iteration includes points for building, testing, and accepting features.
Stories are focused on testable business features.... |
I'm making a .NET application where I'll have a lot of data entries. This will not go to any server though, but needs to be stored and updated, frequently on the local machine.
I would like something like an SQL database, that simply exists in a file, in my application's folder (or in %appdata% or whatever).
But how do... |
I'm reading algorithms and I understand most of it, one thing that I can still struggle with a lot is something as simple as running times on different for-loops. Everyone seems to have easy with that, except for me and therefore I search help here.
I am currently doing some excercises from my book and I need help comp... |
If we take the two below entities as en example.
public class Person
{
public string Username {get;set;}
public string DisplayName {get;set;}
}
public class Worker:Person
{
public string Title {get;set}
public int SecurityId {get;set;}
}
When anyone first registers with this app, basic information wou... |
I'm trying to figure out what sort of data structure to use for modeling some hypothetical, idealized network usage.
In my scenario, a number of users who are hostile to each other are all trying to form networks of computers where all potential connections are known. The computers that one user needs to connect may no... |
Basically I have a series of logic in my website that can lead to 5 total outcomes. Basically two different if tests and then a catch all else statement.
For example:
if cond1:
if mod1:
#do things
elif mod2:
#do things
elif cond2:
if mod1:
#do things
elif mod2
#do things... |
My amateur reading of the MIT license suggests that any software is distributed to my customers containing any MIT-licensed components can be freely re-distributed in its entirety.
Permission is hereby granted [...] to deal in the Software without restriction, including [...] the rights to [...] distribute [...] copie... |
For methods that never access instance variable or static variable and they act just like a function (name-spaced) and they are deterministic base on only the input arguments , I want to ask, are there any consideration if I change all of them to static method?
I keep hearing people saying it static method is poor, but... |
I have been taught to follow the Red->Greeen->Refactor pattern when doing TDD. There have been situations where this pattern have not been applicable though.
For instance, a test to make sure that a controller action method (ASP.NET MVC) does not have an Authorize attribute. Since the test is testing the absense of an ... |
Given the amount of material that tries to explain what a context-free grammar (CFG) is, I found it surprising that very few (in my sample, less than 1 in 20) give an explanation on why such grammars are called "context-free". And, to my mind, none succeeds in doing so.
My question is, why are context-free grammars ca... |
I have an email helper class that has a method that sends email:
private static class EmailHelper
{
public static void SendEmail(string from, string to, string subject, string message)
{
MailMessage msg = new MailMessage(from, to, subject, body);
var client = new SmtpClient("my.smpthost.com"); /... |
we have a project structure like the following
"module-shared" module depends on "module-database" module and some other modules depend on "module-shared" but no other module depends on "module-database".
All the DML SQL scripts are stored in "module-shared" but DDL are stored in "module-database".
The advantage of th... |
I am used to user testing in Java, and I also manually test each section of code I write, but now, I want to automate it.
There is no GUI for this project, so user testing is not required and I can focus code testing. The fact is, I don't know how to test code other than by calling the methods by hand, passing differen... |
Using the spl_autoload_register(), should I use a single autoload function that contains all the logic to determine where the include files are or should I break each include grouping into it's own function with it's own logic to include the files for the called function? As the places where include files may reside e... |
Replaceable parameter syntax for the console object in C#.
I am taking the O'Reilly C# Course 1 and it is asking for a replaceable parameter syntax and it is not very clear on what that means. Currently I used this:
double trouble = 99999.0009;
double bubble = 11111.0001;
Console.WriteLine(trouble * bubble);
Am I mis... |
My understanding of how TDD should work is that you write a failing test for the next bit of functionality you want to add to a function or object, code until the test passes and then write the next test. Is it ever ok to write tests that pass with the code as is?
One example of that happened today. I was writing a fun... |
When we build a new machine, how do we add software to that machine?
I know we have assemblers and compilers that convert the high-level code into machine code for it to understand. But having designed a new machine with some new architecture, how do we proceed ahead and add assembler and compilers to a machine unders... |
Sometimes people use the phrase "Polymorphic method/function".
Does it mean:
A method that takes a Polymorphic type as a parameter, and performs some operation on it. By "Polymorphic type" I mean a super-type with multiple sub-types.
An abstract or virtual method in a super-type, with multiple sub-types that implement... |
How does one ensure that HTML, CSS and JS have uniform identifiers. For example, one such set of identifiers could be class names. e.g.:
CSS:
.user-profile{
...
}
JS:
document.getElementsByClassName( "user-profile" ).(...)
HTML:
<div class="user-profile"> ... </div>
Are there any IDEs that can provide this functio... |
There is an open source project which uses GPLv2. It had numerous releases that complied with GPL in the past where source code was available for given binaries. The newest source code is about 18 months old and is being called a last "official release".
Since that OSed "last version" further development has been done ... |
Every C compiler offers the option to "pack" C structures (e.g. __attribute__ ((__packed__)), or #pragma pack()). Now, we all know that packing is required, if we'd like to send or store data in a reliable way. This must also have been a requirement since the first days of the C language.
So I wonder why packed structu... |
Let me ask you, as this bothers me for quite a while but appears to be subjectively the best solution for my problem, if reflective discovery of an inner class for API purposes is that bad idea?
First, let me explain what I mean by saying "reflective discovery" and all that stuff.
I am sketching an API for a Java datab... |
The Strategy design pattern is often regarded as a substitute for first-class functions in languages that lack them.
So for example say you wanted to pass functionality into an object. In Java you'd have to pass in the object another object which encapsulates the desired behavior. In a language such as Ruby, you'd just... |
We usually have a lot of system software inside our PC's like Operating Systems (which contains different interrupt handlers etc.), Assemblers and Compilers, Drivers. My question is how do we store this information in the computer? Are these all softwares stored in machine instruction format inside the computer at spec... |
Recently I decided to start developing a client/service based system using WCF and a Duplex Channel (callbacks from Service to client). The clients will behave as "slaves", that is, they will only connect to server and from then on, only the server communicates with them. Eventually the server may request that the clie... |
The 2nd time I run this program I'd like it to start in the same HDD location as the previous instance. How should I save, or remember, where I was so the program starts in the same place?
I'd like to persist my previous location the same way across MAC, Linux, Windows, ...
Where is a good place to save my location so ... |
According to cppreference, we can use release-acquire semantics to ensure write-read precedence between two threads as follows:
// Thread A
1. Write to X
2. Atomic store to Y with std::memory_order_release
// Thread B
3. Atomic load at Y with std::memory_order_acquire
4. Read at X
Supposing that 2 is ordered before 3 ... |
When working with the 3-layer model, where should the validation code be placed? for: not empty fields, unchecked options, null values, wrong-written dates, etc.
To keep total isolation between a form (UI layer) and the business rules, this validation should belong to BLL?
It's the only work for the UI: grab user data ... |
I've read that Go doesn't actually have true type inference in the sense that functional languages such as ML or Haskell have, but I haven't been able to find a simple to understand comparison of the two versions. Could someone explain in basic terms how type inference in Go differs from type inference in Haskell, and ... |
they are free to move anywhere on the screen weather in straight lines or curved ones just as long as they don't be at the same place at any given time.
btw I'm not asking how to write it in code, but rather the logic if you will?
1- how would you make an object move randomly? (disregarding predefined functions or cl... |
What is throw-away prototyping model in software engineering and why do we need it? How does it differentiate from Evolutionary Prototyping?
|
I have this question which I need answered:
What is the asymptotic running time for the following piece of code?
if (N < 1000)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
A[i] = j;
else
for (int i = 0; i < N; i++)
A[i] = i;
logarithmic in N
linear in N ()
linearithmic in N
quadratic in ... |
My company has many WCF services which may or may not be replaced in the near future. The old web application is written in WebForms and communicates straight with these services via SOAP and returns DataTables.
Now I am designing a new modern web application in a modern style, an AngularJS client which communicates wi... |
Say in a game engine, you have Objects that composited of different components. One of these is a RenderComponent which can be either a Mesh, a Sprite or a Light.
Now, all these are vastly different classes with non-complatible interfaces, so deriving them all from RenderComponent makes little sense. Also, an Object ca... |
I am learning the multi-threading and timer in C# now. But it seems I can't find a good solution.
For example, I would like to see how many addition problems that I can solve within 1 min. I would like my program to have
A digital clock to count for 60 seconds in the top of my Console.
Print a math problem in the midd... |
As per Should I ask my question about which data structure to use here? I'm asking this here. Hopefully this isn't too implementation specific.
I'm currently developing a program that will represent chemical structures (and eventually allow manipulations/reactions of them). I've hashed out two different systems of st... |
When I execute the following loop :
unsigned m;
for( m = 10; m >= 0; --m ){
printf("%d\n",m);
}
the loop doesn't stop at m==0, it keeps executing interminably, so I thought that reason was that an unsigned cannot be compared to 0. But when I did the following test
unsigned m=9;
if(m >= 0)
printf("m ... |
I have some video processing to run and FFmpeg already contains much of what I need. However my videos are all compressed with H.264 video codec and libx264 is a GPL part of FFmpeg. On the other hand, the Constrained Baseline Profile is pretty enough for my application which means I could perfectly use OpenH264. So wou... |
My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this:
err_struct myfunc(...) {
err_struct error = { .error = false };
...
if(something) {
error.error = true;
err... |
I've been using the Builder pattern to create objects with a large number of attributes, where most of them are optional. But up until now, I've defined them as final, as recommended by Joshua Block and other authors, and haven't needed to change their values.
I am wondering what should I do though if I need a class w... |
Ok so my scenario is this:
I have a third party component that offers an API for communicating with an external system. The method calls for commanding the external system to do stuff, all return void.
So what I have done is I have created a wrapper interface and have mocked out the external system. But since I have no... |
Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the constructor with the specific variables, or creating a lot (in this case 100+) of essentially identical classes and hard c... |
Implementing remember me with Stripe, while not using their Checkout (not supported on PhoneGap), seems to be fine using the path:
First time:
Request token on the client side using card info.
Create customer on server side using token.
Upon confirm, charge customer.
Second time:
Check if current user is Stripe cust... |
I have a central git repo located on a server. I have many contributors that are not tech savvy, do not have server access, and do not know anything about git. But they are able to contribute via the project's web side. Each of them logs on via a web browser and contributes to the project.
I have set things up so that... |
Or is the script generally converted to a known language such as C++ first?
And how generally to you integrate a scripting language with the say a game engine?
|
I previously asked this on StackOverflow, but was advised it was a better fit for Programmers.
I have recently begun working on a codebase (as a Java developer) with the following characteristics:
Roughly 800,000 lines of source (including whitespace and comments). Primarily Java, but also XML, PHP, Shell scripts, JSP... |
For curiosity purposes as well as understanding what they entail in a program, I'm curious as to how instance testing (instanceof/is/using dynamic_cast in c++) works. I've tried to google it (particularly for java) but the only pages that come up are tutorials on how to use the operator.
How do the implementations var... |
This may seem like an odd question to some of you.
I'm a hobbyist Java programmer. I have developed several games, an AI program that creates music, another program for painting, and similar stuff. This is to tell you that I have an experience in programming, but not in professional development of business applications... |
My co-workers tend to think that it is better to limit non-domain type suffixes to a small fixed set of OOP-pattern inspired words, e.g.:
*Service
*Repository
*Factory
*Manager
*Provider
I believe there is no reason to not extend that set with more names, e.g. (some "translation" to the previous vocabulary is given i... |
I'm currently developing a WinForm application.
In order to inform the client about the improvements and corrections made during the last version, I would like to manage and display a changelog.
I mostly found existing changelog on website (the term changelog is pretty used) or explanation on how to manage the release ... |
The title says "Circular Dependency", but it is not the correct wording, because to me the design seems solid.
However, consider the following scenario, where the blue parts are given from external partner, and orange is my own implementation. Also assume there is more then one ConcreteMain, but I want to use a specifi... |
I'm currently beginning with the development of a new web application. The whole web application is going to be bookmarkable and all the pages accesible via GET requests and url parameters. Having said that, let's suppose I've got three entities in my application, Customer, Team and City. Each Customer and Team belong ... |
We have planned to take up an user story say
As a player I want to view the game map to know current standings of my team
The sprint is for two weeks. We will be able to complete only HTML in two weeks time, this user story will take 4-6 weeks to be completed as we have a shortage of content designing resources.
How ... |
I am analyzing some running times of different for-loops, and as I'm getting more knowledge, I'm curious to understand this problem which I have still yet to find out.
I have this exercise called "How many stars are printed":
for (int i = N; i > 1; i = i/2) System.out.println("*");
The answers to pick from is
A: ~lo... |
I'm working an API which works as "intermediary" between a REST API and the developer.
In this way, when the programmer do something like this:
User user = client.getUser(nickname);
it will execute a network request to download from the service the data about the user and then the programmer can use the data by doing ... |
By "code style" I mean 2 things:
Style, eg.
// bad
if(foo){ ... }
// good
if (foo) { ... }
Conventions and idiomaticity, where two ways of writing the same thing are functionally equivalent, but one is more idiomatic. eg.
// bad
if (fooLib.equals(a, b)) { ... }
// good
if (a == b) { ... }
I think it makes sense t... |
Given n sets of items. Each item has a value. The items in a set have similar values but vary by a small amount. The goal is to create new sets containing three items selected from the original sets such that the total of the values is within a given range. Only one item a source set can be selected.
For example: If we... |
I have a class SuperClass with two subclasses SubClassA and SubClassB. I have a method in a different class which takes a SuperClass parameter.
The method should do different things depending on the type of the object it receives. To illustrate:
public void doStuff(SuperClass object){
// if the object is of type Su... |
I've always wondered why one calls a function as opposed to, for example, executing it.
A Google search for function call etymology and similar terms turns up nothing useful, Wikipedia doesn't mention it, online dictionaries have either no entry at all or no etymology section.
Where did the notion of 'calling' a functi... |
I, for the life of me, cannot find any literature on this, simply because I have no clue how it is called.
I want to learn how to implement a payment option that consists of paying with your credit/debit card directly without the use of a third party like paypal.
This is what I am talking about
Can you please give me ... |
Assuming a language with some inherent type safety (e.g., not JavaScript):
Given a method that accepts a SuperType, we know that in most cases wherein we might be tempted to perform type testing to pick an action:
public void DoSomethingTo(SuperType o) {
if (o isa SubTypeA) {
o.doSomethingA()
} else {
o.doS... |
I have a design and am wondering what the appropriate way to access variables is. I'll demonstrate with this example since I can't seem to describe it better than the title.
Term is an object representing a bunch of time data (a repeating duration of time defined by a bunch of attributes)
Term has some print functiona... |
I recently have completed a language library that acts as a giant filter for food items, and flows a bit like this :Products -> Recipes -> MenuItems -> Meals and finally, upon submission, creates an Order.
I have also completed a database structure that stores all the pertinent information to each class, and seems to f... |
I'm working at a company that uses Excel files to store product data, specifically, test results from products before they are shipped out. There are a few thousand spreadsheets with anywhere from 50-100 relevant data points per file. Over the years, the schema for the spreadsheets has changed significantly, but not un... |
I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully understand them. Currently, I have some code that looks like this:
var fields = options.fields || ['id', 'query'];
I ne... |
I want to hash "user + password".
[EDIT: prehashing "user" would be an improvement, so my question is also for hashing "hash(user) + password". If cross-site same user is a problem then the hashing changed to hashing "hash(serviceName + user) + password"]
From what I read about salted hash, using "user + password" as i... |
Consider I am going to write a simple file based logger AppLogger to be used in my apps, ideally it should be a singleton so I can call it via
public class AppLogger {
public static String file = "..";
public void logToFile() {
// Write to file
}
public static log(String s) {
AppLogger... |
Usually, I consider a large number of parameters as an alarm bell that there may be a design problem somewhere. I am using a Generic Repository for an ASP.NET application and have a Controller with a growing number of parameters.
public class GenericRepository<T> : IRepository<T> where T : class
{
protected DbConte... |
I have scenario, where I got stream and I need to check for some value. If I got any new value I have to store it in any of data structure.
It seems very easy, I can place conditional statement if-else or can use contain method of set/map to check either received is new or not.
But the problem is checking will effect... |
I have a software product. it will probably run on VMs that have no network connection at all.
I want the user to pay for each VM the user runs.
I thought to ask the user for some kind of hardware ID and provide him with serial that is unique for his machine.
But user can just copy the VM image and than have two machin... |
I'm working on an application that creates music by itself. I'm seeking feedback for my OO design so far. This question will focus on one part of the program.
The application produces Tune objects, that are the final musical products. Tune is an abstract class with an abstract method play. It has two subclasses: Simpl... |
Some of our business logic classes require quite a few dependencies (in our case 7-10). As such when we come to unit test these the creation become quite complex.
In most tests these dependencies are often not required (only some dependencies are required for particular methods).
As a result unit tests often require a ... |
I have attached a RGB LED to a color picker on a webpage and have hit the obvious problem that though the LED takes 8-bit values (like HTML) the color rendering is very different so with the more subtle shades the LED values for the color are wildly different to the HTML values.
The brute-force method would be for me t... |
I have a class that has three methods A(), B() and C(). Those methods modify the own instance.
While the methods have to return an instance when the instance is a separate copy (just as Clone()), I got a free choice to return void or the same instance (return this;) when modifying the same instance in the method and n... |
A couple of weeks ago I delivered some work for a university project. After a code review with some teachers I got some snarky remarks about the fact that I was (still) using Data Access Objects. The teacher in question who said this mentions the use of DAO's in his classes and always says something along the lines of ... |
While there is a similar question focused on Java, I've been in debates with utilizing Task objects. What's the best way to handle returns on CRUD methods (and similar)?
Common returns we've seen over the years are:
Void (no return unless there is an exception)
Boolean (True on Success, False on Failure, exception on ... |
I am a third year bachelor student in a software engineering program, and I brought up the idea of reading SICP to an adviser to gain a deeper and more fundamental understanding of the principles behind all this software we engineer.
He suggested not to learn Scheme to complete the book (because it's not as common as m... |
I've been reading up about the repository pattern, with a view to implementing it in my own application. Almost all examples I've found on the internet use some kind of existing framework rather than showing how to implement it 'from scratch'. Here's my first thoughts of how I might implement it - I was wondering if an... |
Not sure on my tags for this question, but in short ....
I need to solve a problem of packing industrial parts into crates while minimizing total containing area. These parts are motors, or pumps, or custom-made components, and they have quite unusual shapes. For some, it may be possible to assume that a part === re... |
A lot of apps, for instance, have a free version and pro version. Do programmers, when a new update is released, remove lines of code that shouldn't be available in the free version? As for Visual Studio. Or demos. Or a lot of things actually.
|
In Head-First Design Patterns, they use a pizza shop example to demonstrate the factory method pattern.
public abstract class PizzaStore {
public Pizza orderPizza(String type) {
Pizza pizza;
pizza = createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza... |
I'm currently working in an industry where extensive documentation is required, but the apps I'm writing are all pretty much cookie cutter at a high level. What I'd like to do is build an app that asks a series of questions regarding business rules and marketing requirements to generate a requirements spec.
For example... |
I'm a LAMP-stack dev who's been more on the JavaScript side the last few years and really enjoying the Model + Collection approach to data entities that BackboneJS, etc. uses. It's helped me organize my code in such a way that it is extremely portable, keeping all my properties and methods in the scope (model, collecti... |
I am currently working on a numerical processing system that will be deployed in a performance-critical environment. It takes inputs in the form of numerical arrays (these use the eigen library, but for the purpose of this question that's perhaps immaterial), and performs some range of numerical computations (matrix pr... |
I have the following two classes:
public class StoreService : IStoreService
{
private IEmailService _emailService;
public StoreService(IEmailService emailService)
{
_emailService = emailService;
}
}
public class EmailService : IEmailService
{
}
Using Ninject I can set up bindings no problem t... |
Bjarne Stroustrup mentions in his book "The C++ Programming Language, 4th Edition" that not all C++ implementations use files to store and compile code:
There are systems that do not store, compile, and present C++ programs
to the programmer as sets of files.
(Chapter 15, page 419)
Later in the chapter, he reiterat... |
First of all, I'm not asking where does business logic belong. This has been asked before and most answers I've read agree in that it belongs in the model:
Where to put business logic in MVC design?
How much business logic should be allowed to exist in the controller layer?
How accurate is "Business logic should be in ... |
I'm faced with similar classes A1, A2, ..., A100. Believe it or not but yeah, there are roughly hundred classes that almost look the same. None of these classes are unit tested (of course ;-) ). Each of theses classes is about 50 lines of code which is not too much by itself. Still this is way too much duplicated code.... |
We've been in the process of changing how our AS3 application talks to our back end and we're in the process of implementing a REST system to replace our old one.
Sadly the developer who started the work is now on long term sick leave and it's been handed over to me. I've been working with it for the past week or so no... |
My .NET application creates HTML files, and as such, the structure looks like
variable myData
BuildHomePage()
variable graph = new BuildGraphPage(myData)
variable table = BuildTablePage(myData)
BuildGraphPage and BuildTablePage both require access data, the myData object.
In the above example, I've passed the myData o... |
I am working with an existing application built on Rails 3.1/MySql with much of the work taking place in a JavaScript interface, although the actual platforms are not tremendously relevant here, except in that they give context.
The application is powerful, handles a reasonable amount of data and works well. As the num... |
I am developing an angularjs app. The app has to run in current FF, IE, Chrome and on iOS/Android via Phonegap.
I am looking for a solution to store data in the client.
Phonegap offers a web sql api, that is also supported by Chrome. FF however does not support it, since it is abbandoned by w3c.
Cookies and localStorag... |
I'm writting a German specification (I'm not German).
Differences may appear for this process in different cultures, especially in the terminology, but usually here's the idea:
The client writes his needs and wishes in a document, called a scope statement or requirements document.
The supplier tries to understand the ... |
I was recently browsing a open source JavaScript project. The project is a straight port from another project in C language. It mostly use static methods, packed together in classes. Most classes are implemented using this pattern :
Foo = (function () {
var privateField = "bar";
var publicField = "bar";
fu... |
Let's pretend I am going to work on an enterprise application. Say I have 11 modules in the application and I would have to develop Dashboards for every role in the organization for whom I are going to develop application.
We Decided to use Asp.Net Web Api and return json data from our apis.
We are going to include 11... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.