instruction stringlengths 34 36.1k |
|---|
First of all, I want to say I wasn't sure if I should post this here or in math.stackexchange but I think the question is too programming-related to belong to the latter community. Definetly not a SO question, though.
A brief introduction of my program: I am developing a scheduler for sport events using CSP. Each event... |
So I'm coding my first projects in C++ and it seems that it takes more effort to make the code "clean", rather than merely work. I.e. it seems as if C++ "allows" to write ugly, but working code.
Which got me thinking,
Can a programming language enforce clean code by design? Are there such languages already?
Also, how i... |
Our agile sprint lasts three weeks. Say 40*3 = 120 hours. Our boss requires us must to log at least 8 hours every day. We use JIRA to record time. However my current story in the sprint estimated time is about 15 hours, of course it is not enough. Because I have to search online, discuss with team members and watch tra... |
Background
I have to call a method that needs to return a signed integer (see code block below) after converting from an unsigned integer. The reason for this is that I have to do bit-wise math that relies on the value starting out as an unsigned integer.
I was thinking of doing the try/catch with checking method that ... |
For example, if I had a Customer class and wanted to get all orders by them. Would it be better to do:
class Customer{
public function getOrders(){
return results from db query
}
}
...
foreach($customer->getOrders()){}
or
class Customer{
private function getOrders(){
return results from d... |
Is this a good or best way to configure a web site HTML to add mobile users?
My site pages add Googles default meta viewport, and all code is simple (basic CSS, no frills), but flows well into narrow screens.
It uses 10% margins for readability if wide, but if screen max-width is < 800 pixels, it reduces margin to 1%.
... |
I'm building a web application project that in my view behaves differently in specific environments. I have dev, int, uat, prod environments. DEV is a local environment for developer and 'int' is the integration environment that gets deployed on a remote machine on every commit and runs automated test cases communicati... |
I have been trying to figure out an efficient algorithm that can check if a list of values contains a list of values. Both lists are sorted in ascending order.
For example:
Check if
var listToSearch = [1,2,3,4,5,6,7]
contains
var searchValues = [1,2,3]
Without iterating through the list for each value in searchValues.... |
I think I may be writing -too- many unit tests.
For example, say I was doing a coursework management system, and I coded a feature for submitting coursework on behalf of a student. If invalid credentials are specified in the API call, a 401 forbidden is returned. If a student tries to submit a different student's cours... |
I'm currently drawing a use case diagram (using UML2.0) and it's getting quite large and unorganised.
So my question is, is it acceptable to place actors on both the left and right of the system boundary?
I have seen several examples of this but I'm not sure if there are specific reasons why actors are placed on the r... |
I wasn't quite sure where to post this, but this place seemed appropriate. I've noticed during the time I've been doing web development that I waste more time configuring and setting up my environment, than actually making an application itself. I've tried using lots of tools such as grunt to automise tasks but I still... |
Does anyone know why something like cj library for complex numbers was never completed and integrated into mainline Java?
This seems like a no-brainer... I realize the Java gawds don't want to turn Java into C++ but this is a thing that C++ handles beautifully and this guy's implementation (written 17 years ago!) hand... |
In the book Database Fundamentals, Silberschatz. It is explained that aggregate functions can be calculated on the march.
This make sense. What it means is that for calculating the maximun, average or count the items in a set, you don't need to pass a copy of the set to the aggregate procedures, you only process each r... |
Lets say I have an Organization and Users inside that organization.
To get a user in particular organization what should be the GET request url from below options?
1. /api/organization/:orgId/users/:userId
2. /api/users/:userId?organizationId=orgId
Any other suggestions are welcome.
|
I'm running a Django application service with an API that feeds to a javascript frontend. The data is specifically for charts and graphs, so the data that is returned is a fairly large json with every call.
The frontend specifies some parameters they want the data to start and end from, including the timezone. e.g.
GE... |
The main languages I use are C++ and Java.
Both languages support exception handling.
I confess, I may not actually understand exception handling, at least, I certainly don't understand why you would need it.
I want to build on this question here:
Defensive Programming vs Exception Handling?
The debate between defensiv... |
I would think it would be a massive breaking change if something like this were to happen on a widely deployed language like C/C++, but maybe it has happened in the past.
Bonus related question: How much should one rely on operator precedence when coding something? Should I save on those ()s?
|
I'm having trouble seeing the benefit of setting the Activity field on Tasks for use in Capacity Planning (I'm using the Scrum Template). In fact, doing so seems to make things more cumbersome.
Why would I want to try to balance out my time between Requirements, Design, Development, etc.? I would think that the actual ... |
I was working on a bit of code for a personal project, when I came upon the need to generate checksums on large amounts of files. First off let me say I already solved this problem ideally using System.Threading.Tasks.Parallel (.net net, C#), which behaves have I would expect. What I expected was several checksums runn... |
I'm looking at this commit which was committed "26 days ago" and the parent commit which was committed "25 days ago". How can the parent commit be committed one day later than the child commit?
|
Consider following JavaScript code:
function foo(ary) {
// some long operation on ary
}
function bar(ary) {
// some long operation on ary
}
function baz(ary) {
// some long operation on ary
}
function main(ary) {
setTimeout(foo, 0, ary);
setTimeout(bar, 0, ary);
setTimeout(baz, 0, ary);
}
main([some large... |
my brain is a little stuck as I am trying to compile an example for my blog. I am presenting an algorithm that draws a number from an array, adds it to a sum and calls itself recursively.
func solve(coins: Array<Int>, target: Int) -> Int {
func _solve(coins: Array<Int>, current: Int) -> Int {
var candidat... |
When should class diagrams, data flow diagrams, and flow charts be made? After making classes or before making classes?
Should data flow diagrams and flow charts be made all the time in all the projects or it depends on some factors? Which factors would they be?
If the developers are short of time, what out of data fl... |
I am in the process of standing up my first OSS Java lib (GitHub/Maven) that an open source hardware community will be making fair/moderate use of.
I am writing this library with Java 8 and managing its build with Gradle 2.4. Later this year Java 9 will be unleashed and I'd like to actively maintain separate versions o... |
So Clean Code says you should separate each task to a single function (and add these functions a correct name).
I like the idea, but I've faced this problem so far: you receive a parameter which you want to use also on the topmost function, but you need it on the lowest level as well, so you have to pass the parameter... |
http://www.javaworld.com/article/2073723/core-java/why-getter-and-setter-methods-are-evil.html
If you need to change the way the object is implemented in such a way that the type of X changes, you're in deep trouble.
If X was an int, but now must be a long, you'll get 1,000 compile errors. If you incorrectly fix the p... |
class A{
private List<T> list;
public int getListSize(){
return list.size();
}
}
class B{
private A objectA;
public int getSizeOfListInA{
return objectA.getListSize();
}
}
class C{
B objectB;
// here I need to know the size of the list
}
I'm oversimplifying here, ... |
I am currently working on my PHP skills and at the moment I'm working with classes. What I want to do is to create a class for which I can echo the object. I have the following example:
class good_stuff {
public function __construct() {
return "This is a function called by a construct from a cla... |
I have a program that needs to generate temporary files. It is written for cluster machines.
If I saved those files to a system-wide temporary directory (eg: /tmp), some users complained the program failed because they didn't have proper access to /tmp. But if I saved those files to the working directory, those users a... |
Unlike many libraries SDL and OpenGL are designed to provide global resources; you can access them at any time from any class. There are justifications for this: They are written in C, meant to be readily cross-platform and designed to be fast.
They are not object oriented though, and global state is supposed to be a V... |
According to what I know, a variable in Python is a name that refers to a value stored in the computer memory, like a label on a box.
but in other programming languages a variable is a location, in memory, where values are stored, and it's like a box.
Why does that difference exist?
Python Documentation doesn't tell ... |
In F#, a tail recursive List.filter function can be implemented like:
let filter f =
let rec filterImpl f acc = function
| [] -> List.rev acc
| h :: t -> filterImpl f (if f h then h :: acc else acc) t
filterImpl f []
But it can also be implemented by a closure (i.e. without passing f explicitly... |
Everyone has heard this term thrown around, and most people, I would imagine, have a conceptual idea of the meaning. I, myself, am in that latter group. However, I feel that the definition Google/Wikipedia has provided me isn't great.
Code refactoring is the process of restructuring existing computer code – changing t... |
I have 1000 LOC that I plan to refactor into different files and functions. The goal is to be able to test the business logic independently from the visual display. Hence, I am considering an MVC pattern.
One of the challenges is that I repeatedly need access to (properties and methods of) a unique instance of an objec... |
Having difficulties deciding which rules to apply on by value / by name evaulation.
Say I have:
(λz.zz)(λb.b)
And I want to evaluate according to call by valute, will the next step be
(λz.z)(λb.b)
(evaluate the left side - z apply on z),
or
(λz.(λb.b)(λb.b))
(evaluate the right side first)
And how does the evlua... |
My co-worker has been assigned the task of editing one of our Java application's tables. She is almost done, but needs to make one final adjustment to the table - this requires her to add a CSS attribute to a single table cell so that it does not wrap to the next line.
However, she's informing me that 'best practice'... |
So I came across this post while researching about package structuring for MVC. I just need some clarifications on what a business domain and technical domain are. Examples would be helpful.
|
Let's say I read a bunch of numbers from a text file. Each line is initially a string, I need to parse it to an integer. This is where the first exception might happen - NumberFormatException thrown by the Integer.ParseInt method. This is a runtime exception - unchecked exception that I don't have to catch or decorate ... |
When VLAs were introduced in C 1999, I thought it was a great innovation to the language. However, having learned it was made optional in C 2011, I am wondering what led to its change in status, and if it means the feature is actually headed for obsolescence. If so, is there an equivalent notion of automatic management... |
Our codebase is old and new programmers, like myself, quickly learn to do it the way it's done for the sake of uniformity. Thinking that we have to start somewhere, I took it upon myself to refactor a data holder class as such:
Removed setter methods and made all fields final (I take "final is good" axiomatically). T... |
I don't understand the actual point of Node.js and Zend routers. I feel like they are trying to replace the query string, but I only see examples of single level routes. For example this is what I thought
"Old school" queries
www.site.com/catalog.php?size=10&colour=black&style=3xz
Routers
www.site.com/catalog/3xz/10/b... |
Suppose that we are modelling a form using DDD; the form may have certain kind of business rules associated with it - perhaps you will need to specify an income if you are not a student, and you are required to list your children if you indicate that you are married. And if you specified a country, then it should have ... |
So:
main does a loop, and every iteration it increments a tick by one
For example, say it were in python because that's easy to write:
def main():
tick = 0
while True:
tick += 1
I want to trigger many different events every n-in-x ticks.
So I could skip nine-out-of-ten ticks using modulus:
if ticks ... |
This question is more theoretical than practical. Imagine we have an intelligent machine that if is fed with a fully complete specification of an object then that machine will produce exactly that object, and not anything else.
Now, can we ever achieve a fully complete specification of anything?
If you want a more prac... |
We are developing a Web API (ASP.net, C#) project and use Bamboo CI for our continuous Integration. We run the Unit test before the deployment task so that deployment does not happen if test fails. We deploy to a development server. My questions are
When should I run Integration test in build process before or after d... |
We are building a web service with an idempotent create method and we are looking for approaches on how to implement idempotency.
The created objects have unique identifier properties, named Id, which is a GUID type and assigned by the consumer.
We considered these approches:
1) Check if an object with the same Id exi... |
What is Self-compilation (a.k.a. Meta-compilation) in Forth? How it works and why is it useful? Does it have any practical usage and is it still used in modern systems?
|
Is it because the advantage of copying a array into another array is that you can have the data added onto the array itself, rather than just referencing a particular memory location?
|
Until now I didn't find anything good about monitoring a DB's specific table (or related tables) specific values changed. I want to know:
Since most of DB's don't support monitoring changes for specific rows/values/columns, how to link them together? (I mean I don't want to use something like Timer or loop to check whe... |
In which order should code in a single lisp file be organised? Is there any common style guideline that allows other lisp programmers to easily understand code?
Googling for lisp style guideline yields plenty results; among them:
Common Lisp Style Guide by Google
Community-driven Emacs Lisp style Guide by Bozhidar Ba... |
Should code that positions a form be in a seperate class or within the form itself. It is assumed, that there will be only one form using it.
A class definitely encapsulates the behavior and the state, but maybe it is unnecessary indirection in this case?
|
Assume your app doesn't need to work offline. Also assume that you want to render some fresh data from server -> Redux store for that data is invalidated every time it's rendered.
Does it make sense to store such data into Redux store? Creating reducers for data that is invalidated anyway seems like waste of time.
|
Could anyone explain which one of the two snippets below would be best practice for initializing a static final List?
Initialize when declaring:
public class Sample {
private static final List<String> myList = Collections.unmodifiableList(Arrays.asList(
"Cache-Control",
"Content-Language",
... |
I want to feed an HTML5 data grid with large data sets that the client will want to manipulate in different ways, e.g. aggregation, grouping, pivoting.
The data comes from different web services and the client will be carrying out transactional operations on it.
The data grid will contain various controls for manipula... |
I have a class that only has one method. This method has to read csv file, do some work concerning internal logic (check if item already exists, do some transformations, etc.) and finally write all data to a database. I am using a nested class for storing data from csv file as a list of objects. It looks something like... |
I have a PHP app and 90% of the code is about managing multiple MySQL tables. But there are other systems like a User system and an Admin system, etc. All PHP requests are processed in one App file, so this file needs to dispatch requested commands and send along params. The question is, where does the routing end and ... |
I have a bunch of repetitive C++ code that looks like this:
// Compute finalOutput if possible. Return true if successful, false otherwise
// finalOutput only holds a valid value if true is returned.
bool getCompositeValue(double& finalOutput) {
double output_1 = 0
bool success_1 = hopefullyGetSomeData("Data_1", ou... |
I was trying to communicate with a coworker about a JavaScript error I was being notified about in my browser's console window when I realized that I wasn't sure if I should refer to this as a compiler error or a runtime error; especially if said error is only popping up when, let's say, a certain button is clicked. Th... |
I recently read somewhere that calling a function within a loop is considered bad practice. Is this true? So for example, if I had the following:
function foo(value){
console.log(value);
}
var bar = ["Foo", "Bar"];
for(var i = 0; i < bar.length; i++){
foo(bar[i]);
}
Is it bad practice do do this? Should ... |
I want to work on uemacs/PK and run it through Coverity SCAN. I can see on the repo that there are commits by different people, but I'm confused because the README only allows modifications by a particular person.
Full screen editor based on MicroEMACS 3.9e
MicroEMACS was written by Dave G. Conroy and
grea... |
Is there a standard or widely accepted term for referring to a variable within the current call of a recursive function where the last value of the same variable is passed as an argument? I am trying to comment a complex recursive function and I feel as if there is going to be a communication barrier between how well I... |
In our web application development project, we need a feature that lets the users to email themselves an attachment (~1MB) which resides on the server.
I was considering two alternatives.
Upon clicking on the email button
Download the attachment to local folder and attach it to a new email window in outlook. The flaw... |
I'm reading the Project Valhalla proposal to add value types to Java. It's arguing for explicit value types because the compiler can't automatically move allocations from the heap to the stack very well even if the objects are immutable (all fields are final) because it can't know if some code won't suddenly check the ... |
Let's say we have a function that checks if a given pattern occurs in a string. The default behaviour is that if the pattern matches, then it returns the pattern. So far so good but what is the recommended way to handle the case where the pattern doesn't match. There are many alternatives of course but I can list two:
... |
I'm writing a library function that takes a list (or "bunch") of items (let's say Student) and does something with them. What's the best way to write the function signature in the interface?
std::vector<Student> The problem with the is that maybe my caller isn't using STL and then they need to instantiate and populate... |
I'm trying to grasp the concept of an operating system at the moment (on Unix-like machines)
The kernel is the process with PID 0. Of course the Kernel is not really "just another process" because a process is a concept of the kernel, but it's not like the kernel yields control to some other component (...?).
Everythin... |
I need to write simple http client. It could be great to have unit tests for my class. But I don't know how to write proper and testable class.
For example, I have a client like this:
class HTTPClient
{
public:
HTTPCLient(const std::string& host, const std::string& port): session(host, port) {}
void send()
... |
In general, I know that global variables are bad and should be avoided.
Are static global variables equally bad?
In all my projects, I have heavily relied on static global variables. From design perspective, how can I avoid using them.
Ex Use case :
Whenever the key is changed(by some other threads), my call back notif... |
Consider a store with multiple branches and a system generates reports for each branch monthly and annually and an overall report as well monthly and annually.
So in total there are 4 types of reports
Monthly branch-wise report
Monthly overall report
Annual branch-wise report
Annual overall report
How are they to be... |
I'm trying to understand the idiomatic way to code. I'm using gmock to unit test the components I write. Gmock requires methods to be virtual to be able to mock but the class I'm trying to mock has a non virtual method that I would like to be mocked out.
So the options are to either mark the methods as virtual or crea... |
I am reading book "Foundations of Qt Development", Chapter 12, and I read that threading is platform-dependent, can someone explain, why? I know how to use threads but that what they said is not so clear to me.
|
I have the big use-case diagram:
May I pack some use-cases in packages and then show diagram by the following way:
|
I have stream (magnitude 10s of millions) of entities, say Item which is modeled as below:
class Item {
String id;
Double price;
Double profitPercentage;
Country originCountry;
Country destinationCountry;
...
}
All the attributes of this entity are well defined, and are restricted to Price related information + ... |
I have a huge list of matrix i.e A = {M0, M1, M2 .. Mn}.
I have a task to find the product of all the matrices in a given range {x,y} i.e Mx * Mx+1 * Mx+2 ... * My.
I would like to know if there is any algorithm or data structures that might efficiently compute this query.
I have tried creating a 2D matrix of all possi... |
I have a collection of non-self-overlapping simple polygons P. In actuality, they are 2D triangles in 3D-space.
I'm looking for a data structure which, given a line L, has a relatively fast lookup for all polygons p in P which L intersects with. If it can give me the intersection point, that is a bonus, but I can calcu... |
Which is the preferred design to use, one constructor that allows null, or two constructors where one throws an ArgumentNullException on null?
Two constructors with exception throwing
public class Foo
{
private IDictionary<string, string> _bar;
public Foo()
{
_bar = new Dictionary<string, string>()... |
Booch gives 4 main concepts (principles) of OOD (see his book Object-oriented analysis and design with applications ):
Abstraction
Encapsulation
Modularity
Hierarchy
Usually we encounter to these 4:
Abstraction
Encapsulation
Polymorphism
Inheritance
Are those equivalent? Should I understand Modularity as another te... |
I find css quite hard to read sometimes. Indents, depending on the dom structure, would greatly increase readability. Consider the following example:
#page {
text-align:center;
font-weight:bold;
}
#page p {
white-space:nowrap;
} #page p:hover {
display:inline-block;
}
#page .... |
Here is a code I have got from here:
class Deletor {
public: virtual ~Deletor() {}
};
template<typename T> class Base : public Deletor {
public:
int Run() { return static_cast<T*>(this)->DoIt(); }
};
class Derived1 : public Base<Derived1> {
...
public:
int DoIt() { /* the actual i... |
Often I find myself solving bugs by finding the answer on Stack Overflow. Is it bad practice to add a snippet of why I did what I did and then add a link to an article or page from the web?
|
Often times I see questions on the Hot Network Questions list like this that basically ask "how do I draw this arbitrary shape in CSS". Invariably the answer is a couple of blocks of CSS or SVG data with a bunch of seemingly random hard-coded values that form the requested shape.
When I look at this, I think 'Yuck! Wha... |
I'm not sure of the proper terminology here so I'm having trouble finding the answer to my question but here is what I want to achieve.
say I have
class ABC {
public:
int number;
};
and I want to add a function inside int number's scope (I think is how you would say it). something like IsNeg() but I would like to... |
I'm developing a windows forms c# application for a client with sqlexpress database. It contains simple CRUD operations using sql DataReader, DataWriter. My problem is how to install the application for the client to use in the easiest way.
I'm going to install sql express and .net framework in the client PC. But I do... |
Problem Statement
At our company, we have various application projects that we work on and then we also have libraries that those projects need to utilize. I feel the need (based on some similar question that have been asked) to say that none of these libraries are from a 3rd party, and that we design all of them in-ho... |
Over the last two years, I've taken over a web application development group. My focus for the first two years was building teams, get technology updated and in-place, and fixing my customers pain points so we can begin moving forward.
We recently starting building new applications in MVC, and I'm finding that my ju... |
One thing I do not get with C#'s using Directive is why I can only "use" a namespace at file level, and not within any arbitrary block scope.
(using namespace x; of C++ does allow this and certainly the C# designers where aware of this.)
If I have, e.g., one single function in my class that does something with file I/O... |
I plan to have a web server, which will serve JavaScript used to make connections, and a socket server which the javascript will talk to.
How can I make sure that when deploying a new update, the javascript and socket server are on the same version and so don't get confused. Do I have to restart both at exactly the sam... |
Is there anyway I can create a loop for System.out.println("...") and reading in the values? For example I wish to do this:
System.out.println("Input the Executive's name: ");
String eName = input.nextLine();
System.out.println("Input the Executive's address: ");
String eAddress = input.nextLine();
... |
Question
Is there a rough consensus if the bitmask 0x01 is properly said to have the "zeroth" bit set, or the "first" bit set?
If there isn't rough consensus that there's a generally right answer, is there at least rough consensus that there is a contextually right answer (e.g. that how the code is semantically using t... |
Clearly the prototypical "Hello World" program does not suffice to demonstrate the difference between the major paradigms of programming. What would be the minimal program to show the differences between procedural, object-oriented, functional and reactive programming?
|
In this article by Alex Papadimoulis, you can see this snippet:
private void attachSupplementalDocuments()
{
if (stateCode == "AZ" || stateCode == "TX") {
//SR008-04X/I are always required in these states
attachDocument("SR008-04X");
attachDocument("SR008-04XI");
}
if (ledgerAmnt >= 500000) {
//... |
My Windows desktop app creates a file in:
%LOCALAPPDATA%\XYZZY Software\Our Product\foobar.json
One customer on Windows 7 is experiencing "Accessed Denied" errors when our software tries to overwrite this file. This file was created by our desktop app, exactly where Microsoft recommends our app saves its internal data... |
I would like to create a website for a local school and then offer it to others. The school's main headache at the moment is capturing student marks and comments at the end of each school term. The student data on their current system can only be modified by the admin staff, who don't always have the most up-to-date in... |
I read couple articles about Consumer Contract Testing, but I cannot find answer to one question.
Let's say I have 3 microservices: A, B, C. The communication looks like that:
A -> B -> C
Now I want to test contract between A and B. Should I start services B and C or only B in mocked/stubbed mode?
|
I have a "Product" class that has some ID, and multiple other fields, and a function updateProduct(id, Product update). The intention is that "update" only contains the changed information - other unchanged fields may be missing or null.
I currently have some code similar to the following:
Product updateProduct(long i... |
The application goes something like this:
Users download app and upon downloading, a unique barcode will be presented to them.
The barcode (via phone) is scanned at the checkout (so it eliminates paper receipts).
The receipt will then be send to there phone because of there unique barcode.
I am wondering two things:
... |
What's a good way to store loads of sorted string on a file so that inserts and reads are fast?
I could store it up in a tree, and read/modify/store it as needed, but that seems wasteful for operations like 'seeking the nth object'. Isn't there an indexed data structure that's used specifically to store and retrieve s... |
I am developing a program which is to be installed on a "simple" machine in a LAN, the only particularity is that the NIC are connected on mirror ports.
The software can scan and monitor the network. What I am looking for is a technique to take down a host on this network.
When I discover a new host on the network I wa... |
I have an app that was created from a follow-along tutorial. I was first using the Apache license for it until some people began to copy the code, insert ads and then redistribute the app. Would there be a license that allows for code changes but bans redistribution?
|
Mobile app: (Patient)
I've developed an android mobile application which you can register, login, enter your personal information, enter your blood pressure factors, heart rate, and blood sugar. In addition I've considered a place which the user by pressing a button will download the doctor's prescription, to say how m... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.