New answers tagged

3

In this case, would it be acceptable to do a check for file existence in the constructor? No. Frankly, it's not acceptable to do the null check in the constructor. (Why? Because very few people know what the behavior is when you throw from a constructor. Is the object created? Can you use it safely? What about if the constructor is in the middle of a ...


2

I deeply believe in fail fast myself. The idea is to help debugging devs by getting them as close to the cause of the issue as possible so they don't have to slog through file after file trying to figure out where a bad value came from. However, file I/O is not something you should pretend you control. You don't. You're never going to. You test that the ...


0

Seems like the provider class should expose a method that actually does the providing and error checking. Then your class and constructor can be nice and simple (or just take in whatever other dependencies are needed) and not have any side effects. This also lets you add other methods to the class to support different data types or functionality without ...


0

I have never heard of fail fast as a software design principle. I view fail fast as a project or organisational strategy where one wants to learn of project failures as early as possible so one can course correct or abort while limiting the cost of having gone in the wrong direction. It's a risk mitigation strategy when there are a lot of unknowns. I will ...


4

Am I using namespaces wrong? Wrongly. It's an adverb. And the answer is probably. In use cases, which would you prefer? There are several reasonable tests. Is one easier to read, easier to say, easier to type, easier to fit in a readable expression or otherwise easier to use? Can you take something out without impairing clarity, legibility, usability ...


1

Following the advice we got from the community, we have decided to alter our architecture to assume that our database technology will know how to use transactions (or some other equivalent). We will have a master object that transactions will be fed to. These transactions can contain any number of destructive queries (insert, update, delete) in whatever ...


2

Having a short look into Axiomatic Design Technology, when I got this right, I think it is pretty simple: a "design parameter" is simply a module or component in a software system which has the purpose of implementing a specific functionality or feature within the application the idea of "one design parameter to one functional requirement" is simply called ...


0

You should implement this as two columns, and use two rows for reciprocal permissions. Barring some exotic circumstances, this situation is better designed as a table with two columns - one for the permission holder, and one for the subject. If you need reciprocal permissions, you'll have two rows on said table. (as pointed out by @AntP). A table having a ...


8

In general DI should be supported in libraries. The actual implementation or selection of a DI Container should not be done by a library, that should be left to the root application. That way the root application can decide on whether or not to use DI what DI library to use which other dependencies to load/pass on to the library DI support can be ...


1

Object oriented design The alternative without Hand class is continue to use a List and write all the logic about compare hand in a module Hand Evaluation. What you suggest is not impossible, but it's orthogonal to an object oriented approach. In OOP, you define concepts (objects) which represent a state. A hand, a given selection of cards, is a prime ...


0

My dilemma is that rule 2 and 3 are only true after validation of rule 1. Since only Foo is public no client can misuse the individual rule functions however an other developer could get a new requirement and use rule 2 or 3 without first checking for rule 1... And? The code that other developer writes won't then work. The thing is, this is only ever a ...


0

I want several intermediate functions to make my code more expressive Assuming your first example was the correct one (they aren't equivalent and the second one is buggy) let's first try to make the logic here a little more readable. public bool Foo(arg) { if (arg.attr1) { if (arg.attr2) return false; else if (arg.attr3) return false; } ...


0

If the outcome of Rule2 is only valid when the outcome of Rule1 is valid, executing Rule1 as part of Rule2 would make sense. That way Rule2 will never be executed on its own. The concern that Rule1 will be executed multiple times (separately or as part of Rule2 and Rule3) is a technical problem (assuming that the execution of a rule has no side-effects) So ...


1

I would model this with a state change request table. It would refer to the object and the kind of change (publish, delete, replace content). If the request is approved, the state change is executed. Special consideration would be needed when multiple state change requests are in flight.


0

A cache is the correct solution. I would keep the signature of the cache the same as the conversion function. If a conversion function converts a string to a string, I would keep the cache a Map. You'll want to pick a fixed size LRU cache so infrequently used items don't clog the cache.


5

Preface. Much of this post is for "using C++ lambda as closures to reduce dependency and coupling" in general; therefore it contains advice for such code in general. The sample code here seems to satisfy all advice given here. Using a C++ lambda as a closure in this case is totally acceptable. It is recommended too, since it reduces coupling and header ...


0

My personal example comes from the Linux kernel: struct firmware { size_t size; const u8 *data; struct page **pages; /* firmware loader private fields */ void *priv; }; There are various fields that the system can configure, and the firmware-data is read-only. But, that is not the point (read on). This design is also in line with the ...


2

What the user assumes the inputs - trial options - are […] Don't allow the user to make such assumptions. With more that a handful of options, the user will guaranteed get some of them wrong. Instead, let the user give each combination of options they want to use a descriptive name before starting a simulation. Then the user can recall that set of options ...


-2

try this instead. I would use the additional status field and i'll create dropdown so that maker can select "submit" and approver can select"approve" so that the same update will be done on my database


4

The diagram should fit your purpose. The "best" practice therefore depend on your intentions and your focus: Is it a high-level design model to show the responsibilities of your core classes? Then, focus on the core interactions between Gamer and GameService. Is it a detailed design for implementing a complex communication layer? Then you may want ...


-1

This is a very old topic but one that has jumped into my view at this late stage and I'd like some comments as I try to make a case for write-only properties... I have a set of ActiveReport classes that are part of a website that are instantiated and run on postback after a number of user selections. The VB code looks something like this: Public Class ...


2

I think you are right, you seem to have explored the space and the limitations that the language imposes. The issues you had with the first method is that 1, it didn't have shared attributes and that 2, it required at least one function to be able to store it in the same interface. Shared attributes are a way to store state. If this is your intention then ...


3

According to the requirement, this data is for viewing only therefore should not be downloaded by user. As you know, viewing something (henceforth called “document”) from internet requires downloading it. You could add extra steps… However, you also need to provide the client the code to do those extra steps… Then the user can take the document after your ...


4

is symmetric encryption useful? what are other drawbacks or security vulnerabilities it would introduce? No. The user can just intercept the data after your app has decrypted it. In general, what is a proper way to prevent or make it difficult for users from downloading restful resources? The proper way is to not worry about it. The user can always take ...


2

It's not possible to know for sure whether caching your data in Redis would be worthwhile without more information, but: Don't jump to the conclusion that you need to cache the data in Redis. Every dependency you add to a project has a cost. Once you add Redis, you have added one more potential source of problems. When debugging your program, you will now ...


0

I'd say the problem here is the concept of the FieldGrid as an array of Tiles. You limit yourself to a classic implementation of the game where the UI, an ascii display, is tightly coupled to the game itself Fine if that what you want, but then you don't really need the Snake class. The snake is just the collection of SnakeTiles. A more modern design ...


2

You are at the right place for a review of your design. But this is not a code review site, so don't expect an in-depth inspection here. Overview What strikes me first looking at the classes is that: there is no relation between the Snake and either FieldGrid or Tile: it feels hard to believe that both could be as independent as this diagram suggests, ...


3

The idea behind "separate databases" seems to be one that's misunderstood, and I've written about it before here. Having separate databases does not mean separate database server hosts, or even processes. The idea is that the data stored by different applications is isolated. Coming from a background in relational databases (particularly MySQL), this would ...


3

One of the driving ideas behind microservices, is to have independently deployable components: if team A makes a change on microservice a, they should be able to deploy it whenever they want, and team B should be able to deploy their change on service b at their own pace. Sharing a common library is on one side a good thing, because you reuse proven code....


0

I am not sure it solves anything in your particular case, but it can be done. An example: Let's say you are using C#, with Entity Framework Core for database access. In this case all your microservices (the ones made in C# at least) will use Entity Framework Core. In other words, they are all sharing the same library. "But this is not a library I build ...


0

I would recommend reading Event Streams in Action - it will go over some of the design choices, such as Passing data by reference vs. including all data in the event proper Railway processing and dead letter queues Registering and evolving event schemas (With avro and a schema registry)


0

Depending on how deep you want to get into the Domain Driven Design woods, you could consider Event Storming. Doing one of these will highlight the domain events etc you should be interested in and how they relate to the rest of the system. Note that domain events are not the same thing as events in event sourcing. But understanding them will help you ...


0

I know it will sound old-fashioned, but the most solid way to model event driven systems is through state transition charts (a.k.a. state machines). If you are not familiar with UML, you can do your modeling with an event list. You can do it in a white board, and a very simplified example follows. (Nouns in upper-case are our first approximation to classes ...


6

While I am not an advocate of Big Design Up Front, I'm also not an advocate of No Design Up Front. Some systems are complicated enough you have to think through them. When you have multiple systems working together, and events (or messages) connecting them, there are often multiple teams affected by the mistake. Agile methodology has the concept of Just ...


1

As @Robert Harvey has mentioned in the comments, there is no way for you to know everything before hand. And even if you are confident of the requirements before designing the system, to assume that requirements would not change will bring you nightmares later. You are looking for an extensible design so breaking it down further would help. 1. Renaming/...


5

If I'm understanding correctly, you want to support some operations on the inner array, but not others. If this set of supported operations is general enough for a D2ArrayWrapper to make sense, then I would suggest using an interface. For example, let's say you want people to be able to read cells and rows from the array, but not write them: interface ...


0

Yes, this will work. I've done a SPA out of file storage with API services on Azure recently. You will need to configure CORS on the client and the lambda. The browser will consider the API request cross-origin because it's not going to the site where it got the HTML from. You likely will need a form of external authentication like OAuth/OpenID Connect A ...


0

Here's two ideas and techniques that deal with the question "How much data should be returned in a REST API call?" knowing that REST APIs should be designed for an API user (to make sense from the user's perspective) but not over-specialize on one client or use case json:api introduces a powerful concept of related resources and their inclusion. In this ...


3

A lot of it depends on the access patterns of the data, based on which your database is designed and this further influences your design of the microservices. You can think of splitting your entities along verticals (as in Books, Authors and Relationships in separate tables), which in a way automatically leads to 3 different microservices. Of course, in a ...


4

There is a misunderstanding here. Microservices are not designed to work “on a limited pool of data”. Microservices are designed to be losely coupled, independently deployable and scalable. An effective pattern to support these objectives is to let each microservice have its own database. Why ? a shared database might limit scalability; a shared database ...


2

I find this depends on how generic you need the microservice to be. Say you have a microservice which sends emails. You might have a bunch of tables for addresses, body, attachments etc, but the user of the service wont know or care about that. They will just send a single blob of data and expect you to send a bunch of emails. However, you might have ...


0

What are your requirements for Size of the data (is that 5000/second?) Latency (until data can be viewed, is it 5 seconds, 5 minutes, next day) Retention (how long to keep it) Archival (does it get removed from view but stored somewhere for long term analysis) As a general principle, you should Log unprocessed events with rich details as they are ...


0

Obviously we are guessing a bit but I would say No. You say you want to use these events to product reports, so splitting them in advance doesn't make sense. You dont know what kind of report will be needed. I would put them all in a standard relational DB Table Event Id Type UserId Action Since we are only ever inserting this should be ...


1

To get a different allocation than everybody the same portion, you can extend the IFighter interface with a Share property, which indicates (in a double) what portion of the gold should be given to that party member. A value of 1 should be the default and if everybody has a share of 1, then they all get an equal portion (give or take the left overs after ...


3

I would not put any "setter" for Gold into IFighter, and only implement a setter for this property in the Person class, not in the Group class. The amount of Gold for a group is the total sum of all the gold of all group members, that makes sense. But when gold is assigned to a group, how it is distributed specificially to each person is specific game ...


2

The class responsibility means the purpose of a class expressed in terms of things that it should take care of. The term emerged with the CRC cards (Class, Responsibility, Collaboration), an XP technique that was presented the first time in 1989 by Beck & Cunningham in a paper about teaching object oriented thinking: Responsibilities identify ...


2

Reactive programming - at an abstract level - deals with decoupling flows using asynchronous data streams. However, pretty much the industry standard for achieving asynchronous data streams is through event-driven paradigm, and most of the Reactive implementations use this approach. If there is a better approach to create decoupled flows, then Reactive ...


0

This doesn't answer your actual style question, but note that, in ES6, you can use the rest / spread operator to simplify and arguably clarify your code. In the simplest case below, the caller must remember to spread their array before calling your function: function capitalize(...words) { return words.map((word) => word.toUpperCase()) } console.dir(...


2

I would keep MQTT out of this. You already identified the problem with having too many separate channels, and this is the one to drop IMO. I see two main arguments here: MQTT ports and protocol may be unsupported by restrictive policies such as implemented in corporate firewalls and public wifi access points. https-based protocols are available in more ...


1

Consider your problem domain, and what's the most common use case. If 90% of the time, client code will be working with arrays or some other collection type, and if it is preferable to do it that way, say, to encourage cache locality, then it's probably better to just have the array version - it helps suggest how client code should be written. If not, ...


Top 50 recent answers are included