Tag Info

New answers tagged

0

The Wikipedia article for State Pattern has a Java example that illustrates two states, involving two different methods. Those methods can be arbitrarily complex, so I consider a two-state solution (no pun intended) perfectly valid. interface Statelike { void writeName(StateContext context, String name); } class StateLowerCase implements Statelike { ...


0

It looks like you could integrate CheckAccess into a higher-level data-fetching function. var GetSomeData = function(req) { var data = Data.fetch(req.param_id); if (data.userId === req.user._id) { return {'error': 401}; } return {'success': data}; } // ... // in client code var reply = GetSomeData(req); if (reply.error) { ...


3

Is consistency important? If you consider saving data in SQL, why not go with SQL all the way? Anyways... aggregate functions like count is not a feature of Table Storage, so you either need to fetch all rows and count "client side" (can be very slow), or figure out a way to cache the "count" in another entity. It really depends on your data and ...


2

You don't, because gathering requirements is not the job of the customer. It's up to you to figure out what the customer needs and to translate it into a formal spec. The usual problem is that you often don't know the business domain quite well to determine the actual needs, while your customer doesn't know what is technically doable, and what is not. This ...


0

The speed of downloading and uploading small files can easily be circumvented by putting several files into an archive (eventually with level 0 compression if files don't need to be compressed, which is the case for example for JPEG files). If the user uploads hundreds of files, this will result in two-three large files. If the user needs to upload only one ...


5

So if a thousand people are following Sally, we insert a thousand rows into the corresponding table. Is that scalable? Yes, provided the database tables are properly indexed. What happens if we get to the point where tens or hundreds of thousands of users are following Sally and she's making a few dozen posts per day? You'll generate a few dozen ...


3

Is the top-down design methodology I am describing here a valid approach? Does it have a name? Yes, it is called top-down design, and there's a decent Wikipedia article. In particular, you're describing an informal variant where you figure out what you want the library to do and how you want it organized based on how you intend to use it. do teams ...


8

You're describing Acceptance Test-Driven Development. The basic principle behind ATDD is that each software requirement is accompanied by an acceptance test that, when executed, provides proof that the requirement has been satisfied. Acceptance tests are created when the requirements are analyzed and prior to coding. They can be developed ...


0

A database, being data and generally being optimized for storage efficiency and retrieval, does not necessarily map directly to business domain classes. The less perfectly an auto-generated class fits into a proper domain model the greater the code maintenance problems. Database design is now driving domain design. A Domain model should model your domain, ...


2

When runtime efficiency matters, repeating yourself (e.g. unrolling loops) might be beneficial because some work that should be made at runtime is done earlier. Ideally, such things should be done by a compiler. Also, when you work with a language that does not offer the kind of genericity that would allow you to avoid repeating yourself, you might need to ...


2

DRY exists for a reason, because the more places that the same code exists, the more chances there are of bugs arising from one of those places not being changed when the system needs to change. It is also, obviously enough, easier to test if you only have any given part of your code in one place. Consequently, in most cases where I need to do something more ...


6

There's always a time when you simply have to break a rule, even if everything you know as a coder says there must be another way. Good examples of when DRY may not be the best strategy to use right off the mark include: Code that, for all you know, is a one-off. I generally have a "three-strikes" rule for refactoring; "make it work, make it clean, make ...


1

The problem with lower level languages is not that it "may be a good idea" not to stay DRY when using the specific language. The problem is that it can be hard to impossible to stay DRY if your language lacks certain means of abstraction. For example, if your language does not provide any kind of higher order functions (or at least pointer-to-functions), ...


4

SQL Server. Scalar user-defined functions in a T-SQL query prevent a parallel execution plan and can also have other negative effects on performance. Hugo Kornelis explains it nicely here. ...it’s easy to see why using functions to encapsulate and reuse common computations is considered a best practice. But SQL Server isn’t a traditional programming ...


1

What if another property will be added and become optional? I have done precisely this when I needed to inject some new functionality into that method. This does not break existing code; you gotta love that! In my case I bypass the new thing if the parameter is null. I generally prefer to use a more meaningfully named value/enum. For example, ...


7

Original interface design in the question suggested that Map interface mandated immutability, but this violates Liskov substitution principle. Consider its definition: Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T. Consider immutability as the provable property ...


0

No, that is a violation of the Liskov Substitution Principle since you are expanding the implied contract (from immutable to mutable). You could have a Readable foo as the base class, but you need to make extra special care that the code does not imply immutability.


3

If we interpret this question in its most general sense, the proposed duplicate question has perhaps the best answer you could ever get: Too often when you try to design for the future, your predictions about future needs turn out to be wrong. It's usually better to refactor when you actually know how the needs have changed than to overdesign your ...


3

This seems to me to be a straightforward case of the Granovetter introduction operator as applied by the client in a request - the resource receiving the request needs no prior knowledge of the specific external resource referenced (only that it have compatible behavior), and so long as the external resource being referenced is treated as a subject or object ...


3

This, to my mind, depends on the way you use the URL parameters. Passing URLs as actual data you have to manipulate is fine. Imagine a REST service to handle Web bookmarks. Let's assume it associates some metadata with bookmarks (e.g. date added, icon, etc). By the REST canon a request that asks for such data for a particular bookmark will be a GET request ...


0

There's one big piece of the puzzle you're missing: response time. Even if the load were light and manageable by one server, and I can't really comment on whether it is or not, you'd have potential latency issues from having Uber in the US served by a single server residing in Australia or Belarus. If you look at news reports of Uber going down, you'll ...


0

Yes, of course it could. Whether they do is another matter as even Uber will not be running all their business off a single server - they'll have web servers to receive requests, application servers to process the data, and a (clustered?) database server to store the data. (well, I assume they do, chances are they are running it all off a single websever ...


0

I came up with a "hybrid" solution. And you may give it a thought. I understand it's not desireable to modify 3rd party database, or, sometime it is not even possible because you don't have access to client sources, right? In my case, source data did not have anything I can "reference" like "updatedOn" or any reliable timestamps or logs.. I also needed to ...


1

I guess Requests is "request for service" or order. (because there is "completed requests" metric slightly lower) Their servers also constantly get's pinged by drivers devices (GPS and other stuff), users looking at available cars, gps tracking of users, etc. I can't even say how many requests it will be for 1 trip. But if every car pings with GPS every ...


1

They are trying to establish a correspondence between the terminology related to interlocked operations and the terminology related to acquiring/releasing a guarded resource, which is not an unreasonable thing to do, since the former are usually performed in order to accomplish the latter. When performing an interlocked operation for the purpose of ...


2

The reference is to some resource that fundamentally cannot be held by two agents simultaneously. The classical example is a lock, mutex, semaphore or similar construct, and the canonical use case is making a money transfer. If you acquire an unsharable resource before subtracting and adding the amount from the two accounts, and don't release it until ...


1

From here: The easy way to remember the difference between Acquire and Release is that Acquire is typically used when you are acquiring a resource (for example, taking a lock), whereas Release is typically used when you are releasing the resource.


0

I make an assumption that your implementation language is Java, due to the syntax in the description. Your methods getXX and setXX of XXManager indicates that another class is responsible for both creating and using your XX class. Thus it cannot be a private inner class of XXManager. STW has a point in that Manager is a bad word for a class. What does it ...


1

I do not think making decisions about if trial time was exhausted on client is a good idea. This can be easily fooled and can't be calculated with some precision. Since you have a web application, I guess, it would be much better to limit a number of API calls a trial user can make without payment. You can make some tests and map an average number of API ...


0

Is there any standard way of solving this kind of synchronization problem? I believe not, but I can propose a system redesign. Make two API methods instead of one: Method returning event ids for events currently scheduled for the specified date interval Method returning event details together with updated_at timestamp for a given event ids If a ...


2

You're going for something akin to (but not similar) Spring's ApplicationContextAware, where you pass ApplicationContext (which is a BeanFactory) via a setter, so it later can get beans it needs. Generally it is a bad idea, if you only need to inject dependencies: It is not explicit about dependencies it uses. So, it is actually harder to mock, not ...


3

Your dependency lookup looks very similar to service locator pattern, except that often, service locator is static. The benefits of such dependency lookup when compared to ordinary dependency injection are that: You won't find constructors which take dozens of (often mandatory) arguments if they need many dependencies. This makes your code shorter and ...


2

While this is a bit subjective, there are good reasons for using a GUID or other value that is not coupled to the name of a plugin. You allude to the fact that there are several global properties to a plugin: A label, which is user presentation. This does not change the identity of the plugin and may change, for example, due to internationalization. ...


0

There are many concurrency models so you'd better have a good idea about all before you decide which one to pick. For that, I recommend the book Seven Concurrency Models in Seven Weeks: When Threads Unravel. Check the reviews and the TOC and you can see why this is a good book. And it is also recent (2014).


0

To learn about concurrency, use a language that was designed for concurrency. Golang is a good choice since it has built-in support for concurrency and a C-like syntax which makes the language easy to learn for most programmers. It has message passing, mutexes etc which cover almost all of your concurrency needs and which have more complicated equivalents ...


0

You can have a lean, lightweight app and still have a rich object model. If you're using Angular, that means you're probably writing a single-page application and driving the UI from web services. Those web services should provide you with the data you need for the UI. On the server, you can have a data model and application layer as complex as your ...


1

What are some methods for pathfinding in a 3d world? The same as a 2D world. Most pathfinding algorithms work on graphs, and will happily work with an arbitrary number of paths from a node. You might have some challenges building that graph from your existing data structures; and you might need to change your distance/heuristic for how "good" a path ...


1

Overview This is one way to solve that problem. imagine a request. It contains information defining the request (is it an update of data, or is it a request for the current data), and way for the requester to be notified that the request has been actioned, and of its results. Next up, you have a queue. You place the request into the queue, and at some ...


8

"Kiosk" applications like this are notoriously difficult to secure. Your best starting point is to ditch the traditional command line and implement your own shell in its entirety, and to make it the user's actual shell (i.e., via chsh), so they can't slip out of it.


0

Read the garbage collection wikipage then the GC handbook. Perhaps also the old P.Wilson uniprocessor GC survey I'm not sure that your question makes a lot of sense. In practice, a GC is tightly related to the language implementation (or the bytecode virtual machine) it is targeting. Real world GC for compiled languages require deep cooperation between ...


0

As an update, this question was answered here: https://groups.google.com/forum/#!topic/mongodb-user/-1eXvkoxHUw Summary: Keep data in one document, restrict data using MongoDB's built-in projection feature.


-3

I have witnessed and participated in many online debates about OOP. The proponents of OOP usually do not know how to write proper procedural code. It is possible to write procedural code that is highly modular. It is possible to separate code and data and ensure that functions can only write to their own data store. It is possible to implement the concept of ...


4

Naming things is hard. But in my experience, ambiguity like this can almost always be solved by using a slightly more verbose name in the right place. The alternative method names you suggested are indeed ugly; in this example my first choice would be to rename the parameters: public interface Component { int Read(int portID, byte[] outputBuffer); ...


6

The Effective Go article on the official website mentions getters and setters are fine, and even has guidelines on how to name them: Go doesn't provide automatic support for getters and setters. There's nothing wrong with providing getters and setters yourself, and it's often appropriate to do so, but it's neither idiomatic nor necessary to put Get into ...


0

The origin of your confusion becomes clear when you classify the components of your software according to the Quasar software architecture model. By placing the application logic inside - the call to calculate() inside DefaultCalculationResult itself - you have made CalculationResult an A-software (application specific software). At the same time, you have ...


2

"disgusting if-blocks" can be avoided by using polymorphism to replace conditionals, or more specifically, by applying the strategy pattern. In your example, one could have objects representing a "window open" strategy, a "download strategy", a "download window opening strategy", and so on.


1

but adding that dependency to all those classes doesn't sit well with me. If each array is encapsulated inside a data class, it makes sense to add an overloaded operator to that class to lookup the elements. // This code only illustrate the overloaded operator. // The code here is incomplete, and by itself is unfit // for all purposes. // // ...


0

Aside from using a free function, you may want to examine your class decomposition. If you have a lot of classes which have a 3D matrix flattened into a 1D, and they all access that matrix via this calculation, it's likely that they should all have a common class threeDinOneD which they use.


3

You may need to consider some re-factoring. So it looks like we have [Client] -message-> [Server] and Message (and all derivatives of) are stored in the [Common] package. In your comment you explain that the Message contains a function which gets called by either the Server or the Client depending on which received the message, which in turn calls a ...


11

Given that your question is tagged c++, do not use macros! They should only be used for include guards and a few other esoteric uses. The proper solution here is a standalone inline function. Assuming that WIDTH and DEPTH are constants that are visible to the function, here is its definition: inline int f(int x, int y, int z) { return x + WIDTH * (y + ...



Top 50 recent answers are included