instruction stringlengths 34 36.1k |
|---|
Quoth the Javadoc:
Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose source is an IO channel (such as those returned by Files.lines(Path, Charset)) will require closing. Most streams are backe... |
So I have a file to process that contains a command on each line. Currently it's implemented like this(this is a refactoring assignment):
hashmap.get(commandStr).sendCommand();
The objects(4) inside the hashmap, each contain a different sendCommand method.
The thing is each of these method implementations are just 2 o... |
So basically wen I googled on what the "user.dir" property does I got this link to a similar question on stackexchange: Java “user.dir” property - what exactly it means?
So basically the answer given was : It's the directory where Java was run from, where you started the JVM. Does not have to be within the user's home ... |
Docker is becoming quite popular. I've used it as an end-user just 3 times, and it never worked as expected. But assuming it does work, can you please list some actual benefits? And contrast them with install scripts, for example (considering the overhead of the VM and the issues in VM-host communication).
There are tw... |
I joined the middle of a middle size project, which runs already for several years. One of problems is that the document describing the architecture was never written. Now I was assigned a task to write the architecture description.
During the time I working on this project, I gathered all information I needed to write... |
So I've finally started reading Designing Object-Oriented Software and my needle is stuck at a small but important point. I understand that the example I'm about to present might appear a bit out of context, because it's being developed in the book over the last few chapters, but I believe the overall idea is really si... |
We have a few givens:
Developers need a replica of the production database on their machines.
Developers have the password to said database in the App.config files.
We don't want the data in said database compromised.
A few suggested solutions and their drawbacks:
Full-disk-encryption. This solves all proble... |
Usually in OOP world we are told that modularity is a good practice and keeping loose coupling between module is a great thing. Encapsulation helps us achieve this loose coupling.
In Java encapsulation is achieved via access modifiers, in Ruby we have stricter rules via attr_accessor.
But what about Python? I see that ... |
Consider I have a Calculator class, it calculates an Integer. On higher parts of the system, say a MVP presenter, I want to work with an ReactiveX Observable that emits the Integer.
I could do the following:
public class Calculator {
public Observable<Integer> doSomeVeryComplicatedCalculations() {
retur... |
Lately I've started adding this to certain classes in an in-house API:
public class MyClass {
// I usually do this with classes I expect to
// be printed out or tested a lot (particularly
// in the early stages of creating the class/package).
//
// Having one field is not a criteria for doing this,
// j... |
I'm currently working on refactoring the code-base for one of our services. I'm been going through reviewing everything, and I feel it's a bit scattered, and could probably adhere to OOP principles better.
I have three classes that are all derivative of another class Cache. All three of these classes perform the exact ... |
Let's say you have some issue to develop. And as recommended practice it is good idea to use interfaces ( I don't mean GUI, I mean interface or abstract class ). And you can apply two ( I'm pretty sure, but for now I noticed I apply two ) ways:
Design interfaces upfront and then implement them.
Implement classes and t... |
Please excuse my lack of knowledge in programming, but it is true that a business application, e.g. CRM, can be developed using one language (e.g., C++) and later enhanced using a different language (e.g., C#.NET)?
Can we use multiple languages when developing an application?
|
I have been programming into a number of languages like Java, Ruby, Haskell and Python. I have to switch between many languages per day due to different projects I work on. Now, the issue is I often forget to write self as the first parameter in the function definitions in Python same is with calling methods on the sam... |
Whenever I read something like this:
Many programmers exhibit a slight, involuntary shudder whenever
multiple inheritance is mentioned. Ask them to identify the source of
their unease and they will almost certainly finger the so-called
Deadly Diamond of Death inheritance pattern. In this pattern, classes
B and... |
I would like to understand what would be the optimal method of finding minimum tree coverage of tree nodes. Let me explain.
I have a self-referencing structure that represents a tree, with a limited depth of X.
Nodes in the tree can be logically "selected". From the application perspective, it means that user would li... |
I'm guessing the answer is no because there's quite a few examples, including right here. If I let users submit their own HTML text and then render it side by side, what could the user do that would break the rest of the page and how can I guard against it?
I imagine escaping the input as soon as they enter it would be... |
I was looking to create an EAV structure for an inventory management system. But I read this answer and decided against it. I am looking to create multiple tables for all my products. But the trouble now have is that all the products will have categories and sub categories( only two tiers ). How can I create tables to ... |
What do you think, is C programming language low or high level?
There are some information, in one is said that C is low level, and another C is high level? When I read book of Dennis Ritchie and Brian Kernighan, there is written "C is a relatively "low level" language"?
|
I have heard that when testing stories developed in the current sprint, no issues are raised they are not completed (i.e. definition of done was not fulfilled) and that you should only raise issues when you find another, unrelated issue etc. While it does make sense not to raise issues on something that developers stil... |
I'm looking for 2nd & 3rd opinions on a general mobile strategy for a website I work with. We have decided that tablets generally have an acceptable experience with our site (especially in landscape orientation) but mobile phones do not.
The site has an extensive and well-documented back-end, and recently (~1.5 years ... |
Is there any conceptual limitation that would make impossible to create a C program line by line as in 'Mathematica notebooks'[1]?
[1] One key aspect of Mathematica is that you can create your code line by line in a format called 'notebook'. This makes it much easier to debug the code during the development phase. Afte... |
I would like to implement an algorithm but I guess it's a well-known problem and it has been implemented yet, but I am unable to verify that without its name.
Here is what I am willing to do :
I have a list of assertions that can be either true or false
I have an "oracle" that can tell me how many assertions are true ... |
I'm learning Python, more specially parallel programming using Python Parallel Programming Cookbook by Giancarlo Zaccone.
At the time the book was published async/await was still in the beta version of Python, and so, the book doesn't cover it. It covers Asyncio. Now with the release of Python 3.5, async/await has bee... |
My question is as simple as the title says -- should I implement AST with parent or not?
Currently I implemented it with parent -- the benefit of that approach is, that whatever I use, I can go up or down without any problem, all I need is some node. And modifications to the tree are also easy, because they are local t... |
I have been asked the following question..
An algorithm considers n elements, sorts 5% of n out, considers the remain elements(95%), sorts 5% of the remain elements, and so on until finally one last element is left. Which complexity does the algorithm have and why?
|
I want to make it possible to edit shared todo lists in real time.
There's already a REST interface, and it's possible to send updates to the server - add items, mark items as done, etc.
For the client to get these updates immediately, I did some research, and it seems that the best approach would be websockets, as the... |
I have long experience in procedural world and been programming/maintaining OO code in various languages too. Now getting into OO design and feeling the pains of identifying objects from scratch. Been reading several books, articles, etc. on OO. Often times they stop with Person, Employee examples. Identifying and doin... |
This is yet another follow up question about Object oriented design in general. I am trying to break them down to separate questions per advice I got from @Jay earlier.
I get a new question, almost every step of the OO design process. I tried to get the ideas from books, articles and the web. It just gets more muddied ... |
We have an internal API that is specifically for our website and internal applications, and we are planning to release a public api exposing some of the endpoints in our internal API.
We are using semantic versioning and our internal API is at version 6, would it make sense to just create a new project and start at ver... |
Is there an easy way of comparing any two different size of string text to see how much percentage they're alike?
I'm trying this but I'm running into to this issue below. The left text area is the text to copy. The right is the user trying to copy the text ( in this example the user didn't get everything typed corre... |
I'm unsure whether this post is allowed, considering it may be subjective. However, I have seen many posts concerning naming conventions (on programmers, as well as on StackOverflow - where I'm a more active member) so I think it should be valid. (Though it seems that sometimes topic with naming conventions are quickly... |
I am working on a table that has a compound primary key that includes a date.
Faculty
PersonId StartDate EndDate Title ....
-------------------------------------------------
I will add a compound key consisting of the PersonID and StartDate. The business rule I am thinking about is allowing a person added a... |
Note: The code sample is written in c#, but that shouldn't matter. I've put c# as a tag because I can't find a more appropiate one. This is about the code structure.
I'm reading Clean Code and trying to become a better programmer.
I often find myself struggling to follow the Single Responsibility Principle (classes and... |
I encounter this issue when I create REST API.
I cannot tell the exact scenario, but let's say it is for a website that has category and product resources.
Each category has many products and both category and product are ordered.
I originally add an order incremental integer attribute to the resources so both collec... |
(preface - boring stuff, feel free to skip down to the implementation details)
I need to provide exception handling to a language I am working on. It "compiles" to a subset of C, and since I don't want to make C++ a dependency, and found the few available C libraries rather stiff and lacking, the only way is to come up... |
I and two university colleagues of mine are designing a simple CMS software for a university exam using UML. Such software just needs to deal with sending an article, assigning an article for review, sending a review and scoring an article. Our solution expects a 3-tier client-server architecture, with tiny clients req... |
So I have a Person object, and a GumballMachine object. The behavior I'm searching for is, in the intent to avoid unnecessary coupling, have the method insertCoin() called from within the Person object, which will then call the insertCoin() within the GumballMachine to receive a Gumball.
What is a proper design-pattern... |
Let's assume I have an object a of a class A. It has a method that needs an argument in form of another object of a particular type - but the argument should also be in particular state, because the operation performed by the method (let's say it's querying an external service, but it could be something else) requires ... |
I'm working on creating my own scripting language for learning purposes. I've been reading through the Dragon Book and some things are a little unclear to me regarding the Symbol Table as well as where the strings that constitute an identifier actually reside and the ownership. Most of this confusion I think is due to ... |
BWT backward search algorithm is pretty straightforward if we only need the multiplicity of a pattern. However I also need to find the suffix indices (i.e. positions in the reference string where a pattern occurs). e.g., given string banana and pattern an, it occurs twice at positions 1 and 3.
I could compute all suff... |
I'm trying to put together some basic models in OOP (C#), and apparently I've got the wrong idea.
If I have a Workman's Comp case, it is applied to a Patient. It also has one or more PatientVisits applied to the case. Each PatientVisit though, also has a Patient associated with it, and of course a Patient can have an... |
There are times where using recursion is better than using a loop, and times where using a loop is better than using recursion. Choosing the "right" one can save resources and/or result in fewer lines of code.
Are there any cases where a task can only be done using recursion, rather than a loop?
|
This is a question that perplexes me about object oriented programming.
In some OOP languages (e.g. C++) a member function can access private variables of the class without restriction. That means one can define methods that take no arguments and change the private variables. Isn't this considered bad programming prac... |
Let me describe a hypothetical scenario, I wish to know if my reasoning is correct.
I use source code X, licensed by author Y under the BSD-3 license, in my source code. I intend to adhere to their BSD-3 license.
Then I sell my product under my custom closed source license. My product does not include any source code. ... |
I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't.
The second answer to this question made me to ask for clarification (since i can't comment yet, i made a new question).
So let's take given code as an example of case where one needs gene... |
I'm writing a Java application, I need to create a URI Scheme.
I've seen a library creating a URI Scheme using the "regedit" command on Windows.
Is it safe to execute "regedit" for this task? Is there anything I should avoid or do in a application that is using the command?
|
I'm making a prototype for a game. I'm working on effects at the moment, but more generally animation.
Currently, I have list where newly spawned effects are added to. Then on the update section of the game loop, I'd let each effect change their state based on time. When an effect finishes, I have it trigger an in... |
Background
I am currently working for a quite large (relative to what I have done before) hobby project. I would like to compare the size of this project to other open-sourced projects but I cannot figure out how I should do that in a good and meaningful way.
Problems with using line count
I usually see project size be... |
I was reading up about branch predictions and cache misses, and have decided to read what every programmer should know about memory. But I'm not sure how much low level knowledge do I need to have to write performant code.
One classic example is accessing the memory in the wrong way, accessing column by column when it'... |
The situation is a bit more complex than the title suggests (but not much).
I'm working on a REST API that will have a few open / publicly available resources and a few with authentication. (The latter is currently BasicAuth, but may in the future become something else.)
Obviously, I'd like to have HTTPS for the authen... |
I was tasked to update some conditions in an application.
I have a data set to be evaluated, and it has been hard-coded in the application following way:
$arr = array(
'a' => 'apple',
'b' => 'orange',
'c' => 1,
'd' => 2,
'e' => 5,
'f' => 'green',
'g' => 'red',
'h' => 'yellow',
)
$res1 = ($arr['a'] == 'apple') ? TRUE :... |
I have what I believe is a fairly common situation these days: I have a webapp that scales horizontally across multiple machines in order to serve greater load. This particular application is written in Java.
On this same webapp, I find that I have a need to run a background process in this webapp periodically. However... |
What is the docstring convention in Python for the following "magic" class methods:
__str__
__unicode__
__repr__
Should I add docstrings for these? If yes, what should they say (for each)?
|
I’ve been doing some research on the various approaches to concurrency, and I’ve ended up with the following taxonomy:
Manual thread based concurrency with locks
Asynchronous dispatch queues and callbacks as implemented in Apple’s libdispatch (GCD)
Asynchronous functions, blocking, and message passing as first class l... |
As far as I know, we use story points to measure the complexity of a story in Scrum.
But what about Defect? Should Defect have story points? If it does, what does it mean by completing these points, given that a Defect doesn't have business value like a story? Should we have something different from story points, for ... |
I'm programming a web app using Perl and Dancer. The logic is not trivial and I want to separate the web page logic (inside Dancer routes) from the business logic that reads and writes from the database. The business logic is going to be stored in several modules the read and write in the database using DBIx::Class.
My... |
Why do we need ShapeDecorator in this design? Why can't we just have RedShapeDecorator implement Shape directly and inherit from Shape?
|
Sometimes we have Models and Controllers where the function __construct() just doesn't do anything, but is sitting on the top of all the methods in CodeIgniter's models and controllers. A lot of CodeIgniter books teach it that way.
Following is the example of a __construct(), where it isn't doing anything, and if you ... |
I'm working on architecting a somewhat enterprise-level solution and have a question about how to best handle the persistence details.
My overall setup is that there's a core set of business logic/objects, as well as a number of isolated components that rely on the core logic, but never on other components. Sitting on... |
I usually have if/else conditions which involves comparing values with a constant string.
Is it really advantageous to use symbols in such cases or use string.
For eg.
if status == 'submitted'
...
elsif status.try(:to_sym) == :open
...
Also what are the affects on memory consumption when this condition is in an in... |
In the event an alien invasion occurred and we were forced to support their languages in all of our existing computer systems, is UTF-8 designed in a way to allow for their possibly vast amount of characters?
(Of course, we do not know if aliens actually have languages, if or how they communicate, but for the sake of t... |
I'm trying to understand how stack frames are constructed and have run into this description on wikipedia:
The locations of all other fields in the frame can be defined relative
either to the top of the frame, as negative offsets of the stack
pointer, or relative to the top of the frame below, as positive
offset... |
With all the front end development frameworks now available. I'd like to know if the generally accepted protocol is for a back end service to simply provide web services for the front end to consume?
For example: An application that may have displayed products in the past may have just generated the HTML on the server... |
I've been working on a large project where much of the code is not under test. I have been able to add some unit tests to functional areas of the code, and also to start mocking services but I have a question about how much mocking to do on other areas.
This application and endpoints are primary based on .NET remoting ... |
I am trying to learn webdesign using the MVC design pattern. Right now, I am stuck at a point where my code gets more complex, and I am unsure about the structure and where to put which code parts.
I started with an index.php file as my controller, which right now does not much more than loading the Slim framework to r... |
Suppose you have a type with a throwing destructor, and a function receiving it by value.
Can that operation ever provide anything better than the basic exception guarantee?
Or formulated differently, may one disregard the destruction of the argument which was passed by value when determining whether an operation has c... |
I've recently read an article about Functors, Applicatives and Monads in Haskell and it concludes with these statements:
functors: you apply a function to a wrapped value using fmap or <$>
applicatives: you apply a wrapped function to a wrapped value using <*> or liftA
monads: you apply a function that returns a wrapp... |
BACKGROUND :
I'm trying to use Uncle Bob's clean architecture in my android app. I studied many open source projects that are trying to show the right way to do it, and I found an interesting implementation based on RxAndroid.
WHAT I NOTICIED :
In every layer (presentation, domain and data), there's a model class for ... |
When doing continuous deployment with Git, how do you handle ignored files in gitignore? Those files are ignored for privacy reasons (i.e. don't want them pushed out to other remote repositories, like GitHub), but with those ignored files not being pushed to the continuous deployment repository, they application would... |
I am working in small IT industry and we are trying to implement processes and SDLC into our organization, since we are in initial phase I have few concerns and so want some consultant from experts here:
Currently we create 1 major SDLC documents: SRS.
SRS is initially created by our business development executives wh... |
I am on a project dealing with a lot of data in the form of images and videos (Data related to wind engineering). My requirement is to build a predictive algorithm based on the data I have. I have found many tools with which I can analyse the data where each tool has its own advantages and disadvantages. Big data being... |
I'm using a code generator which has the following workflow:
Configure stuff
Generate code
Modify generated code with user code at specifically annotated positions.
If changes are required to the configuration, the user code will remain after generating the code again because the annotated positions are untouched by ... |
I'm having a distributed environment which include several machines under the same network , which are being controlled by another computer in another network which is also running a UI for doing the operations.
I want to be able to produce some simple parallel interface for being able to do maintenance on these machin... |
I am a computer science student and I have an exam tomorrow on operating systems. I have the exam questions of past years and there is one scenario in a question. There are two tasks in the ready-to-run (I don't what's its name) queue. And the scheduling algorithm is Shortest Time to Completion First (STCF). And two se... |
I just wanted to check that I understand the LSP correctly and can solve it. I am taking the classic rectangle/square problem and attempting a solution:
class Rectangle{
public $width;
public $height;
function setWidth($width){
$this->width = $width;
}
function setHeight($height){
... |
After a discussion with some my colleagues, I've a 'philosophical' question about how treat the char data type in Java, following the best practices.
Suppose a simple scenario (obviously this is only a very simple example in order to give a practice meaning to my question) where, given a String 's' as input, you have t... |
We are about to start an AngularJS project. In fact, the CMS will be AEM (Adobe Experience Manager). I'm now looking into the CSS/layout framework, and whether its worth using something like Bootstrap, when the design team/client has already decided what it will look like.
From what I understand, Bootstrap is very usef... |
I'm implementing an app that has among other things shared todo lists. I want it to sync in real time. This has to work for "normal" single user items (e.g. user has app opened in 2 devices, doing an update in one device shows immediately in the other device) as well as the shared lists, where all the participants have... |
I seem to have a misunderstanding about the difference between <Foo> and <? extends Foo>. From my understanding, if we had
ArrayList<Foo> foos = new ArrayList<>();
This indicates that objects of type Foo can be added to this array list. Since subclasses of Foo are also of type Foo, they can also be added without an er... |
In c programming why I am getting 0 zero for this? Why -5<(unsigned)5 is false?
main(){
printf("%d",-5<(unsigned)5);
getch();
}
|
My application needs to support a "shift change" scenario. Essentially, a person is managing some assets. At the shift change, the person that was there leaves right as the replacement signs in. The assets can survive on their own for no more than three minutes. The server will re-assign the assets if they are neglecte... |
Context
Imagine complicated service that provides info about bank products, fees and so on.
Imagine complicated UI that deals with it.
UI and Service data formats are changed 1-2 times/month because of active development.
Decision
To make life of UI developers easier, we transform data into format that UI developers wa... |
Suppose we have an interface such as
public interface anInterface
{
public void aMethod();
}
and a class as follows:
public class aClass
{
public void aMethod()
{
//bla bla bla
}
}
Now I'm going to define another class such as Subclass that extends aClass and implements anInterface, as in:
public... |
We all know the dangers of gets.
It is also on the way out in C11.
That makes me wonder: how did it ever get into the standard to begin with? Weren't the problems with it obvious at the time of standardization?
|
I haven't studied Smalltalk or Strongtalk and am just trying to get an overview of the semantics of interfaces and polymorphism in O/O languages, particularly Dart.
In the 2002 paper titled Mixins in Strongtalk, there is the following paragraph in the section Copying Down Methods :
If a mixin represents a class declar... |
Let me preface this by admitting that I am a novice - this is the first real project I am doing outside of a class.
I am running a single-threaded C++ simulation several hundred times (i.e. I have several hundred 'jobs'). I would like to be able to have a queue to which I add jobs (perhaps changing a parameter or two e... |
I am developing a public repository webapp for my organization.
It will be public webapp, exposed to the internet. All people and organisational units can be queried and its contact data will be displayed. It is developed as a single page app against a REST back-end. There will also probably be a mobile front-end in th... |
I have a class which is centred around lower-level methods, to make this class much more useful it would be great to put some middle or higher level methods (i.e. methods which make a series of calls to the lower-level methods to do something that an end user may want to do).
I could add the methods to the original cl... |
I'm wondering if I can switch from Java to Scala in a Spring + Hibernate project to take advantage of some Scala features such as pattern matching, Option and what it seems to me a cleaner syntax in general. I've been looking for the ORM by default in the Scala ecosystem and I've found thinks like Activate (but mostly ... |
I need to sort the values according to the following problem:
For every n, determine the triples (i,j,k) that satisfies i+j+k=n, then sort the triples (for every n) with respect to the value of the formula (4*i+5*j+4*k+1) in ascending order. Here is the rough pseudocode:
for n in range(3,N+1):
for i in range(1,n-1):... |
My development background is in ASP .NET webforms. I've been reading various SPA tutorials but they always get into the weeds about specific javascript libraries.
I'm just trying to understand what happens in an SPA with a .NET middle tier.
Specifically:
Does the domain model exist both in .NET and javascript?
Is the j... |
I am wondering what possible merits does copy-on-write have? Naturally, I don't expect personal opinions, but real-world practical scenarios where it can be technically and practically beneficial in a tangible way. And by tangible I mean something more than saving you the typing of a & character.
To clarify, this quest... |
I need to show a refreshable/searchable list of items and update/add-to it whenever an event is published. How do I make sure no events are lost while refreshing/searching is happening?
Some sort of event buffering and locking the list on search/refresh comes to mind, but I am wondering if there is a common reactive lo... |
I have a function which has a large number of arguments.
I want to have the names of the arguments available in the help() function, but I want the results as a dict.
At the moment, I have the following:
def myfunc(thisparameter,thatparameter,hostname,password,port,service,url,someotherparameter, etc, andsoforth):
... |
Consider the following assumptions about C programming (some of which go too far, I confess):
Putting any variable definitions in a header file is incorrect, because each translation unit creates its own copy of the data. And if it's extern and used from more than one place, we get UB. The correct usage is to declare ... |
(Under software architecture/design)
I'm not sure how my question could be subjective but the message next to the title suggests that it is.
I hope I'm not violating the rules here.
Under what circumstances or application would you need absolute precision with thread execution timing( thread sleep, back to life and ex... |
I have concrete factory classes which implement MyFactory interface. I want to get concrete factory objects based on parameter. How to do this?
One way is to create factory of factories[FoF], and FoF would be parameterized factory.
Is there any more elegant way to do this?
This is purely intellectual exercise, I am ... |
This is a design decision that appears to come up quite a lot: how to pass context through a method that doesn't need it to a method that does. Is there a right answer or does it depend on the context.
Sample code that requires a solution
// needs the dependency
function baz(session) {
session('baz');
}
// doesn't c... |
I have a small software that generates some Word documents. It reads a template, runs a few SqL procedures to get the data, generates the documents and then sends them via e-mail. It's quite simple.
Right now I want to apply that logic to generate another type of report, the base word template will change and it will r... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.