instruction stringlengths 34 36.1k |
|---|
According to Is it wrong to use a boolean parameter to determine behavior?, I know it is bad:
public void myFunction(boolean b){
if(b){
}else{
}
}
and it should have separate function:
public void myFunctionTrue(){
}
public void myFunctionFalse(){
}
However, this implementation only moves the if-else fro... |
Constrained by a main loop outside of my control (eg: UI event loop, game loop, etc...), I have a slow (relative to the main loop's expectations) algorithm involving a loop. Thus, I have to restructure the loop to be ___ (what is this term?) so that it can run partially each iteration (not 1:1) of the main loop (ie: sp... |
Everyone is quick to point out the "Rule of Zero" in code reviews, peer conversations, and Stack Overflow comments/answers.
I am not a believer. I'd like to be. Usually if enough people agree on something enough for it to get its own label and become an idiom, then it is well thought out....
So, let me explain my reaso... |
I am currently working on an application with legacy code that was built using proof of concepts (POCs). These POCs became the finished production-ready code, there were no tests, and the classes have become quite large over time (pretty much god objects and there are multiple objects that follow this structure). These... |
I'd like to use Youtube as an example: they use IDs in the form of PEckzwggd78.
Why don't they use simple integers?
Or imgur.com - they also use IDs such as 9b6tMZS for images and galleries. Not sequential integers.
Why don't they use integers (particularly sequential ones)?
In what cases is it a wise decision to us... |
Components common to all ExoPlayer implementations are:
A MediaSource that defines the media to be played, loads the media,
and from which the loaded media can be read. A MediaSource is
injected via ExoPlayer.prepare at the start of playback.
Renderers
that render individual components of the media. Renderers are
... |
Description
Its a follow up question of writing use cases.
Taking from nouns defined in my user story and requirement I found the following candidates to be classes:
User
Question
Session
Attempt/UserAnswer
Score
Category/Topic
Hint
I think the following relationship holds between these objects:
User (o2m) Session
U... |
I am developing some kind of web-based RPG. So for my player domain I came up with this.
player object is going to have a lot of parameters like class, level, name and so on. As it rather plain object I store it in the relational database like PostgreSQL for example. I have an entity RPlayer for that.
Also I wanted to ... |
I have created a Gomoku(5 in a row) AI using Alpha-Beta Pruning. It makes move on a not-so-stupid level. First let me describe the grading function of the Alpha-Beta algorithm.
When it receives a board as an input, it first finds all repetitions of stones and gives it a score depending on its usefulness as an threat. A... |
We have a main MS Sql server. This is the main data source that delivers and receives data to and from backend administration and (in development) mobile software. We need to make a connection to mobile. That is: the mobile application needs to be off- and online available. The data on mobile needs to reflect the state... |
I observed a dubious design pattern in some C# code today used in several methods:
public void DoSomething(bool safe=true)
{
if (!safe) DoSomethingDangerous();
else
{
try
{
DoSomethingDangerous();
}
catch
{
// Log error & carry on
}
}
}
I am... |
Consider I have classes as follows:
public class User{
private String name;
//other code
private String getName(){
return name;
}
}
public class ShowUserInfo{
public void show(User user){
System.out.println(user.getName());
}
}
I'm quite sure I would not have other variations o... |
In Robert Sedgewick's Algorithms book there's this exercise:
A folder is a list of files and folders. Write a program that takes
the name of a folder as a command-line argument and prints out all of
the files contained in that folder, with the contents of each folder
recursively listed (indented) under that fold... |
If something can be generated, then that thing is data, not code.
Given that, isn't this whole idea of source code generation a misunderstanding? That is, if there is a code generator for something, then why not make that something a proper function which can receive the required parameters and do the right action that... |
Given some legacy module in a ten year old project, where you have seen none of the code and not used the application, how long will it take you to grok 10000 lines of code from that module?
The permutations of possible setbacks and or further-complicating conditions is endless, I know. Let the above problem be a fun t... |
I am currently designing a software in which I have to use a rest client. I have decided to use a particular library, but am stuck whether I should use it directly or add a custom encapsulation layer. To make myself more clear, suppose i have to make a request from a function named getAuthInfo.
Doing it directly
func... |
I'm working in the context of a (kind of) microservices architecture where services can have multiple instances that can create new documents in the same collection of a Mongo DB.
There is a functional requirement that each document gets a unique ID (like e.g. an employee ID or badge number). Preferably newer document... |
From my understanding, combinational logic is dependent solely on input, and sequential logic involves state--memory.
When explaining a finite state machine (FSM), however, it is said that an FSM has two combinational functions. However, they both seem to involve memory, in that state is one of two inputs to the funct... |
public class A {
public static void main(String[] args) {
boolean[] test = new boolean[1];
System.out.println(test[0]);
}
}
prints false, as specified by the Java spec.
However,
public class A {
public static void main(String[] args) {
boolean test;
System.out.println(test);... |
I have a doubt with semantic versioning. I'm working with semantic version like is shown in semver
Imagine this scenario:
A stable version, named as 1.1.0
An unstable version, named as 1.1.1-rc1
A bug is discovered in stable version 1.1.0 and you need to fix it asap
1.1.1-rc1 version is deployed in a test enviroment, ... |
We have a few different apps X,Y,X from different third parties and we want to pull the data into a central app C, so when users enter data into C they can pre-populate forms with related data. If they enter a customer-id from app X into C, they will get related customer-id info, address, etc. from X, populating forms... |
I am struggling to find a good architecture for what must be a common problem
Enable/Disable a button in a View that contains a datagrid, and has
validation requirements on the cell, row and collection levels. And to perform this cleanly in a MVVM architecture.
If it wasn't for the datagrid then this would be eas... |
As an exercise, I recently implemented a simple settings reader class which reads setting values from an INI file into an std::map<std::string, std::string>. The reader method looks like the following:
std::map<std::string, std::string> readSettings() {
std::map<std::string, std::string> settings;
for(std::str... |
I'm writing a program in Java where at one point I need to load a password for my keystore. Just for fun, I tried to keep my password in Java as short as possible by doing this:
//Some code
....
KeyManagerFactory keyManager = KeyManagerFactory.getInstance("SunX509");
Keystore keyStore = KeyStore.getInstance("JKS");
{... |
Overview
This is a follow up to my previous question that was flagged as a duplicate, and I do not know what would work better as the title.
Here is a link to the previous question:
Legacy code: what to do in regards to maintenance and moving forward?
And the link to the proposed duplicate:
What is the most effective w... |
We are working on the design for an appointments system which has to work at remote locations, comms via 4G.
Unfortunately a connection to the server may not be available at all remote locations, so data must be pre-downloaded before departure to the off site location, just in case.
The UI should be presented on mobile... |
I have an "easy" question, but since I am not a very experienced programmer I would like to hear what some of you have to say.
If I have for example a Db called MyDb with many tables. Two of them are Company and Address.
The relation between them is that a company can have a lot of addresses (each for one office or sth... |
My question is similar to this one: Storing data in code
Please see the code below:
public class EnglishCurrency
{
public override System.Collections.Generic.IEnumerable<decimal> Values()
{
yield return 0.01M;
yield return 0.02M;
yield return 0.05M;
yield return 0.1M... |
How to save a website of 10 pages in one piece to view it offline (but with CSS and JS in place)?
I tried to save a webpage to view offline from the browser via Firefox:
File > Save page as > Webpage (complete), HTML.
The webpage is saved in a folder containing its HTML, and CSS and JS files but it appears messy, not ... |
Guys, I am a non-technical founder with some understanding of how the web app works front end and backend, etc. I have a somewhat technical question to help me make a business decision. I hope you guys can help me.
I have two different apps built on two different platforms, Express web framework and another one in ROR... |
In my app, I'm implementing a questionnaire system and I'd like to implement tags for questions -- very similar to tags in questions here or Stack Overflow.
I wanted to get some advices on how to implement this as a property in my object. Should they be an array of strings -- as below?
{
"id": 123,
"question": "Wha... |
I have a large number of expressions which I am trying to solve.
List 1 contains formulas like A = B + C.
List 2 contains additional equations for those variables, like C = D*3, C = B/2, B = D*50, etc.
List 3 contains values for those variables B, D, etc.
I then need to compute all possible results for the List 1 for... |
I'm trying to improve the performance, code quality and just make it better in terms of practice overall. I have a server for a game that managers all users connected as well as things like objects and rooms + a lot more. Its divided by rooms, each room will have players and objects placed. During the execution of this... |
A bone-bare example of decorator is:
def strong(func):
def wrapper():
return '<strong>' + func() + '</strong>'
return wrapper
@strong
def greet():
return 'Hello!'
wrapper is an entitled name for the 'inside first-order-function' inside the Higher-Order function strong.
My question is that the word ... |
I would like to know what strategies do you use to deal with A/B tests of your app and gitflow.
Overview:
We are a team of 6 programmers who develop and maintain a large App. So far we have worked on gitflow with a few add-ons on the process added by us which worked perfectly well for a couple years. In a simplified wa... |
TL;DR
How is the new .NET approach to being a multi platform framework
better than what Java did long ago?
What are the key differences in the implementation?
What are the advantages and disadvantages of each?
You can nowadays compile and run C# code "natively" in Linux and Mac. All of this because .NET is going mul... |
We have a story "Scale service to X 000 transactions per second". It's unclear how to do that and how much time will it take. Usually in this case you can define a Spike to find out what obstacles you will face during implementation, what steps have to be done etc., so on the next Sprint planning you have enough inform... |
My system will deal with Google map API to locate user's location after his/her request.
I am drawing the use case diagram and wondering if "Google Map API" should be an external actor to my system or not.
|
Say I have a entity that has "type" attribute. There could be 20+ possible types.
Now I'm asked to implement something that would allow changing the type from A->B, which is the only use case.
So should I implement something that allows arbitrary changes of type as long as they are valid types?
Or should I ONLY allow... |
So I am learning reactive programming, and I am building an app for fun that listens on various stock information tickers, and calculates specific things to show in charts etc.
So right now I have information coming from different sources, each of one is one RxJS observable (think stream), so my "ticker$" observable is... |
Let's assume that we have a service that needs to be initialized, but then it's a singleton. For example, something like this:
public interface IGraphsContainer
{
void Initialize(IEnumerable<Graph> initialContent);
void Add(Graph graph);
bool Contains(Graph graph);
IEnumerable<Graph> FindAll(Criteria... |
I was mildly surprised to find this function in our code base:
public static double ToDouble( object value )
{
if ( value is double )
{
return (double)value;
}
else if ( value is decimal )
{
return decimal.ToDouble( (decimal)value );
}
else
{
return double.Parse(
value... |
Overview
I work in a company where we moved to microservice architecture recently and we are constantly growing our services each day, but I found that we have problem maintaining and monitoring all these configuration files spread across the servers and cloud environments. So I thought myself why not start open sourc... |
Background:
So while Javascript implicitly convert various data types and hence may seem almost type-less(is there such a thing?) it does have different types.
Most of my colleagues seem to think otherwise. The pre-sales and non development colleagues are unaware of this and other developers(90% are senior to me) seem ... |
Why there is common coding convention in PHP. Just like python has pep8 .Some frameworks prefers camelcase but wordpress uses underscore while naming functions and variables which is actually preferred.
|
I am beginning a project and I was wondering If I can use CQRS and Hexagonal architecture in the same project, or in fact they are incompatible.
I read about CQRS and some people agree that it is not an architecture, and more like a pattern.
What do you think?
|
Say I am developing a Calculator application. It has one class called: Calculator. Therefore my namespace structure would look like this:
MyCompany.Calculator.Core.Calculator
Unfortunately, this is not right because the same name should not be used for a namespace and a type in it. This is thoroughly explained in t... |
I have system requirements that the system will send an alert to the user.
This requirement is the most important requirement of my system.
Is it represented in the use case diagram or not?
Thank you.
|
I am trying to understand better MVP Architecture on Android.To do that, i want to implement MVP on android project from beginning.
First i tried to use one module, which is app(Application app),but my app started to grow a little fast than i expected.And testing takes way to much time to finish or i they give me an ... |
Does a programming language team have any tool to validate their new ideas about new code syntax?
As an example, let's assume the Java language team starts developing new feature, which requires new syntax. This feature is supposedly new public keyword, that is allowed to point which classes will see this class. One de... |
I'm designing an web app with React as front-end, and I'm trying to properly understand REST API practices. Reading resources online, one can get the idea that the REST API is seen kind of like an adapter to the database. However, what with "relative" resources? For example the ones related to the current user or the c... |
Edit: Assume that I will stay on this project until "the end".
The Problem
I'm currently working on a legacy interesting Java project(s). A full rewrite is currently out of the question, as I am working alone, and the current desired functionality was due months ago (before I came onto the project).
It is rather l... |
We recently started migrating a ton of small apps from our legacy Lotus Notes system to SharePoint and other internal web applications. In doing so, our developers have been spinning up lots and lots of repositories in our Visual Studio Team Services (VSTS) work space, many of which are single-use migration application... |
While working on an inherited project, I noticed the original dev(s) created many asynchronous functions that never seem to take advantage of being, well, asynchronous. For example:
// The async method
private async Type myFuncAsync() { .. gets something from DB .. }
// Example of how the method is consistently utili... |
In ASP.Net Core, I find Claims authorization is very not-concrete method. We can add anything as ClaimType and ClaimValue pair; groups, firstname, lastname, brithdate, canAccessThisURI, isEditor, etc.. However, this approach (storing anything that can be stored as claims) will make a huge claims table which includes 50... |
I'm designing a system made of a web application and database. I use the <<Entity>> - <<Control>> - <<Boundary>> stereotypes in my UML diagram.
In the following sequence diagram, I already have an interaction with a system in the cloud. I want now to show also the internal database (on the same server). Shall I rep... |
Backstory
A scrum team is well defined. They have a PO, scrum master, clearly defined scope. The workload increases, as more and more projects are covered and need to be maintained, but it is still the same scope.
Problems
Team struggles with capacity, so more developers are added to the team. They pick up, the job get... |
Background
I am trying to develop with Webpack and JavaScript. Webpack would bundle all source code into one single file. When application becomes large, the file would be very large and cause negative impact to the performance.
Webpack
Webpack provided feature named code splitting which would split the bundle output i... |
I just started learning about hamming codes and they're pretty awesome.
I was just wondering though, are the check bits able to detect error in the check bits, as in, if one of the check bits is received erroneously can that be detected? Or is some other method required?
|
Under which circumstances would you deem it justifiable to use externs (i.e. global variables)?
For example, in a system with 1 given state at a time, would it be appropriate to store this state in an extern?
|
I'm working on a small (and very tame) FOSS utility; and I want to test it to make sure that it builds on Mac OSes. But - I don't have a Mac OS I could use for that. I have access to Linux and to Windows boxes, and that's that.
Other than trying to knock on some people's doors and asking for SSH privileges into their M... |
I need to search a long string of binary string data (couple of megabytes worth of binary digits) for patterns of binary digits. There are about 100 000 different patterns to search for. Each is a maximum of 10 bits/character length patterns of 1's and 0's. I then need to display the most common pattern of all of these... |
I have a search algorithm that is used in conjunction with a machine learning algorithm. I separated the two because I wanted to be able to swap out search algorithms on the fly. However, the coupling is currently too tight. It looks something like:
class ML_Algorithm:
def __init__(self,observers):
import ... |
Is there any convention on how to declare, name, use or access object properties that themselves do not add new information and could be re-calculated at any point in time? Basic example (made this one up, just for clarification):
class User {
// provided by DB
int ID;
// calculated
boolean id_is_odd;
... |
Following the reading of the question Why are zero-based arrays the norm?, I wonder about the terms to use for referring to specific array elements, in the perspective of linguistic reading of programming.
Should Array[1] be called the first element of Array or the second element? In the latter case, then how should th... |
I am designing a UI framework in Java. Every UI component, represented by the class Component, in the framework is identified by a non null unchangeable String key. So I get the key in the constructor itself and provided no setter.
Now I have another class AggregateComponent which represents a component containing arra... |
We're currently working on upgrading a small information system for an enterprise. Currently, the system has a corporate network zone (CORP) where services for internal users are placed, and a data center network segment (DC) where a data access service and all databases reside. All applications are essentially deploye... |
I've seen the url like this
domain.com/some-article-title-which-can-be-very-long
many times. There's no ID embedded in it. Therefore, in a db it must be defined as "unique article_url varchar(NNN)"
While it's good for SEO, doesn't this have too much overhead for a database: there's an index on "article_url" and it's v... |
I have a situation in a current application I'm working on that requires featuring batch editing and I'm wondering if there are any design patterns that I should be considering.
The task at hand is given a collection of objects that represent files on disk the user can edit a property on one object and have the edit ri... |
I'm writing code using arm assembly language for college and the I'm really confused about endianess.
The default should be little endian but I'm sure the test string has been stored big endian. The first byte in memory at 0xA1000004 is 0x30 which is 'O', and 0xA1000007 is 'j',
but surely if its little endian the 'j' ... |
I'm trying to write an Entity-Component System and I want to have different factories creating different kinds of entities. For example the HumanEntityFactory class will create human entities.
Would it break separation of concerns if I store the different types of human that the factory can create, or should I create a... |
We have a number of IoT devices that communicate over TCP/IP to a server. Once connected, the server can then talk to the device, get data or send down commands.
The server accepts incoming connections from hundreds of IoT devices on a specific port.
My question is around testing of new code and deployment. Heres my sc... |
(example code in PHP, but this can apply to more languages)
I have a scenario with an adapter pattern, where I have classes, interfaces and objects with different roles, like so:
An original object implementing CatInterface.
A class that implements DogInterface, which wraps a CatInterface object.
An instance of that c... |
I have a system that consists of several applications.
Often these applications need to talk to each other.
Sometimes it can make sense to use a "service account" for the communication but other times it will be necessary to authenticate the request on behalf of the authenticated user.
Because the applications are hete... |
The biggest difficulty I am having is finding where to house the responsibilities of each object identified by me in the system( say on problem space). I am posting a very simplified description of a feature in library management system.
Usecase
As a admin, I can add books to the inventory, or change the "states"
of t... |
I am developing a SAAS application where :
A single web application is hosted in IIS which will serve to multiple companies and each company will have its own database. The web application and databases will be running on the same server.
My question is - what is the best practice to change the database connection st... |
My team is using the Git Stable Mainline branching model and we are about to create the first release branch. From what I have read so far, it sounds like release branches are siloed from the master branch and never completely merged back to master. Instead, if a fix is made on the release branch, then it is usually ... |
I am working in designing Java-based web applications. Although, I have worked with Java core still a novice in designing web-apps and do not have enough confidence in what I am thinking is correct or not?
So, the thing is, we are a team of two, I am working with backend using Java and the other person with the front e... |
I have a class APIClient (Just an example name) which has the methods
def get(url, params={})
@last_response = conn.get(url, params)
end
def post(url, params={})
@last_response = conn.post(url, params)
end
def put(url, params={})
@last_response = conn.put(url, params)
end
def delete(url, p... |
I've always used the tried-and-true "Document and Pray" approach when it comes to conveying the fact that a pointer result from a function (either as a return value or a reference parameter) should not be freed by client code.
The other day someone showed me this function prototype:
const struct foo * const bar(void);
... |
I am working in a governmental institution. The technology being used here and the methods for developing software are quite old fashioned.
They have tons of storage space but no appropriate space to keep and maintain applications that are used to automate most of the work here.
The institution would not allow me to u... |
Say we have a column in table or a property in a collection called "sortOrder" which simply is an integer which denotes which order it is to appear when displayed.
I am trying to figure out the simplest way to implement this, considering that when we insert a new row in the table it may have a sort order which bisects ... |
The example domain problem
There is a student attendance tracking system that keeps records of student attendances of ExerciseGroups.
Course is a top-level component, AR, describes a generic info about the learning course (name, description)
Every Course has ExerciseGroups that describe groups where students can prac... |
I've inherited a somewhat complicated data-model in a SQL Database that I'll soon have an opportunity (read: nececssity) to overhaul. The data-model represents a Product catalog. So there's a table of products with lots and lots of other tables 1-3 generations deep containing category data, localized data, status etc. ... |
I'm currently updating a few very old web Services and came upon a Situation where I'm unsure.
I've got a web Service with the following method Header:
public string MyService(string data1, string data2, int subdatalength, short internalTimeout)
The data provided for the Parameters Comes via SOAP. So far I get it how ... |
I've been in an argument at work about writing readable code. It was mainly about variable and method names and the idea that comments are worthless if the code is readable enough. I would not like to emphasize only on no specific coding language.
1.) Descriptive vs minimalistic variable and method names
Descriptive v... |
Currently, I'm using these methods on HTTPS protocol:
SSL to secure the communication between two endpoints
CheckSum to generate a hash token that only the two endpoints can generate
Is there any way to detect that a specific request comes from the whitelisted server?
|
I'm evaluating the use of Kafka to implement Event Sourcing in a microservices environment that already makes use of an API Management platform.
I was wondering if it is common and/or considered a good practice to use the API Management as a gateway to the Kafka topics. The benefits could be analytics, caching, rate li... |
I want to write my own command line library from scratch. What algorithm should I use in order to parse gnu style args like in getopt for example ? I mean what's the best way other than tokenizing and parse them in a naive way? Should I try to look at LR, LL algorithms or this is way too overkill?
|
Someone made a comment about some of my code which I thought was valuable, and I wanted to look up the design pattern to learn more, but I'm having a hard time identifying which design principle it relates to.
Essentially I had a Encoder/Decoder object. In one direction it would take a string and return an object with ... |
I was working on a piece of code when I noticed that an if statement could work or crash depending on the order used for the parts connected with and.
You can replicate the problem like this:
boolean func(String x) {
assert x
return true
}
v = "text"
if (v != "" && func(v)) {
println("Hello")
}
Depending o... |
Our team has decided to move to a microservice approach for newly developed features. We've decided to keep a database/datastore per service and to split the services along the business function they perform. As we move this direction we're creating the services as necessary. This means that not only have we created a ... |
I'm writing a high level wrapper around the Python socket.socket object. Specifically, I want to do this for IPv4 TCP sockets (though it would be useful to be able to expand the library later with other families / types). As you may know, the socket module defines these as socket.AF_INET and socket.SOCK_STREAM. Is it a... |
I'm trying to better understand the pros/cons of instantiating vs injecting in a web application type development.
What are the pros & cons for each?
When should they be used (what sort of scenario we looking at)?
|
I have a type of "PC" (i.e. personal computer) that I need to model in C++ (can use language standards as new as C++11, but no newer than that). In short, we have a lot of granularity for components in the PC (in my actual tool, it would be about 10 times the number of components shown here), i.e:
Tower
Motherboard... |
I know that if user is forbidden in an admin's area, I should return 401 or 403 status error code. However, what I want to prohibit an admin for accessing a user's dashboard also? An admin has its own dashboard where he can already see a list of users, hence access to a user's dashboard wouldn't make sense.
What error ... |
I have two lists:
1:
1) A abc
2) A def
3) A ghi
4) B jkl
5) B mno
6) C fzy
7) C xxa
2:
1) vsf
2) jkl
3) fzy
4) xxa
5) xyz
6) mno
7) def
8) abc
I am trying to match each of the continuous sequences from list 1--in this case there are two continuous sequences, A and B-- with its corresponding sequence in list 2, with t... |
I need to decide on a bug tracking solution for our small dev team of 4 developers working on a web-based SaaS tool. There is plenty of products out there to use but one major difference seems to be if you either keep your bugs in a list (for example like GitHub issues or Redmine) or in a kanban board (for example like... |
I'm trying to create a Tower Defense game where minions move through a labyrinth and you can build towers on top of the labyrinths' walls to stop the minions. I'm personally using Python and pygame, but I'm looking for generic design answers that can be applied to any OOP language.
So, since both minions and towers hav... |
Generally, we like to have a common folder for common header files to be shared among various projects in solution but what about googletest since it needs access to all header files of project to test them? Is it the norm for googletest project to include files from target project directly?
Solution
├── Project1
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.