Tag Info

New answers tagged

0

Here is a potential partial solution, though not really a programming solution. Assuming the goal is specifically to have the audio of a music file from your mobile device play on another device, for example, a PC or server, you might try the OnAir player, which has apps for mobile devices, some televisions, and Mac/Linux/Windows computers. If you have ...


1

It happens to be that service is your resource and for some reason it may not be available. What would you do if your client application talks directly to the database. Would you check availability of the database before trying to query it? I would not. I think service not being available is an exceptional circumstance. I would expect my service to be ...


1

Just because a http-ping at time t gets a response, you've still got a large uncertainty that a request at time t' will complete. I suggest you not ping the server if it can be avoided because it is a poor proxy measure of actual availability in the future. If a request is made and no response is received, retry with an exponential back-off interval.


3

I would Check Availability on Failed Action. Just issue your calls normally and if you get a failure, then call the Service Availability function to verify. Assume service is up, if one gets and error, then issue the additional call to verify availability.


1

there is problem in ur requirement gathering 1st u said "...(its the independent record) and then I can proceed with the person_id to create Phone,Email and Address" then u said : If the person creation succeeds but one or more preceding record creation fails then actually Employee creation fails" means it is not independent. lets assume its independent ...


1

B definitely sounds like the only sane choice. A means depending on implementation details of the REST API. It makes the "transaction" very fragile, breaks encapsulation, and other bad things. C I'm not entirely sure what you're saying you'll do with a QBWI (beyond the email to admin part), but it doesn't sound like an actual solution to the problem. ...


0

The way you've worded the question and comments implies that these are not instances of a single database, API, worker, etc, but separate pieces of software for each client. If so, you're essentially making a completely different product for every client, which is definitely not common or reasonable. If this is the problem you're having, you need to decide ...


0

A lot of this could be accomplished with virtual servers. As you grow in clients and expertise, you'll learn how this could be automated/scripted. You will also be able to monitor and decide how to scale the hardware. If your clients are paying for this service, you'll see how this can be marketed and priced so they feel they are getting their moneys worth. ...


8

What is missing in your system is the cache. You say: However, this requires a lot of separate GetUser calls, causing a lot of separate sql queries inside the User subsystem. The number of calls to a method doesn't have to be the same as the number of SQL queries. You get the information about the user once, why would you query for the same ...


0

There is no user interface diagram in the set of UML diagrams (up to and including UML 2.5 beta 2) and the engineering best practices vary. The key search terms would be made of: user interface wireframe mockup prototyping UML behavior diagram Some relevant results (unordered): Agile Modeling: User Interface (UI) Prototypes: An Agile Introduction User ...


0

Do not cache. Technically: As Frank already said, the difference is the garbage collector. If you cache it, your objects will be moved to the java oldspace, where trashing objects is slow and painful. Whereas trashing objects in the new object space, comes at no costs, because this element isn't simply touched any more. But if you keep objects for no ...


0

I would say it depends on your needs. Do you need to know the name of the variable? Do you want the (multiple) variables to be passed in a specific order? Is the amount of variables going to grow (like filters)? Does it need to be part of the url? (i.e. for SEO reasons) I mostly know two variants (different then the examples you gave), and in ...


4

The key factor here is how cohesive the parameters are. If you have a group of parameters that are logically grouped and should belong to a class, then create a class for them. If they happen to occur together in parameter lists but are not logically grouped, keep them separate. Keep this method as-is: function getDistance(Point p1, Point p2) { ... } ...


5

Methods with many parameters are often unavoidable. Since when? I mean it might be unavoidable to have a couple of methods like this in a non-trivial codebase, but the vast majority of your methods will have one or two parameters. Having a boatload of parameters is a sign that: 1. Your function is doing too much. 2. Your boatload of separate ...


1

I'm not sure why people think putting the ID values in the URL means its somehow a REST API, REST is about handling verbs, passing resources. So if you want to PUT a new user, you'd have to send a fair chunk of data and a POST http request is ideal, so although you might send the key (eg. user id), you'll send the user data (eg name, address) as POST data. ...


2

This is where you get it wrong: If my clients pass me an id reference In a REST systems, client should never be bothered with IDs. The only resource identifiers that the client should know about should be URIs. This is the principle of "uniform interface". Think about how clients would interact with your system. Say the user starts browsing through a ...


0

The following is more RESTfull because every grandparentID gets it own URL. This way the resource gets identified in a unique way. GET /myservice/api/v1/grandparents/{grandparentID} GET /myservice/api/v1/grandparents/{grandparentID}/parents/children?search={text} The query parameter search is a good way to execute a search from the context of that ...


2

The Liskov Substiution Principle is by far the best "heuristic" I know of for determining whether direct subclassing is a good idea. Say you have a base class Foo, and derived classes Bar1 through Bar9. In a nutshell, the LSP states that any block of code using a Foo must work correctly no matter which of the nine Bar types that Foo actually is. From the ...


0

One common use is when you want to use the template method pattern. I that pattern you write the skeleton of an algorithm in an abstrac class. In some parts of that skeleton you can certain methods that are not implemented. Subclassed implement those methods completing the algorithm. That can also be achieved without inheritance using injection and or ...


0

Yes ...see the link below for this pattern... If you're writing an application which uses Peers -- or any complex app which requires robust Object-Networks I would use an Event-Driven Architecture. Using a Mediator or EventHub (Event-Aggrigator) The simplest approach would be to implement the Mediator Pattern designed by Addy Osmoni. This allows you to ...


1

It depends on the conventions and guidelines for a specific programming language. In C# it is not easy to delegate methods to an inner object (it requires explicit code). So inheritance can be easier. When creating a public .net based API, inheritance is often recommended, to simplify discovery for the API user.


0

There is a DI framework for C++ (still under development AFAIK): Boost.DI. There are some useful comments about the framework on reddit.


0

Similar to what Robert Harvey proposes but instead of logging or signaling an exception when the boolean switch is true or false, always signal the exception and use a different exception handler depending on the switch. For instance, if the switch means to log silently, your exception handler should do that. Otherwise the exception handler would just ...


1

Disclaimer: I'm not entirely sure I understand what you're actually trying to accomplish here, so my answer is going to be somewhat vague. Cron or Celery (haven't decided yet) will run all the .py files inside scriptFolder every lets say 15 mins Let's be optimistic and suppose you have millions of users some day. Will Cron/Celery be able to get ...


1

If it's just one API or function call, include a boolean switch in the function call that allows you to switch the error behavior. If this is something you want to implement on a system-wide basis, the best way to do it is probably in whatever logging strategy you are using. You can use a configuration setting to tell the logger to either log the error or ...


3

Generally, this is not a good set up, because it's not DRY ("Don't Repeat Yourself"). If it were me, I'd work very hard to figure out how to have one well tested script which can generate the feeds needed by the individual users. Perhaps the script would get per-user information from the database.


2

It's not uncommon to do what you described. In fact, when you create a new database for your user, you basically creating a new file for that user. So, it just adding a file to the set of per user files. The choice of when to do the work begs explanation though. Doing the sign up process in batch periodically can create load spikes on the servers. It's ...


3

It's important to understand that a single method may not be your "unit". To give a contrived example, if (for some reason) you created a class with public methods: Add(object key, object value); Get(object key); which just wrapped a private Dictionary, it would be inconceivable to test just one of those methods at a time, independent of the other. ...


6

Despite established wisdom in writing unit tests, Martin Fowler has said that his idea of a unit is generally "a bunch of closely related classes and treat them as a single unit. Rarely I might take a subset of methods in a class as a unit." So there's no real reason why you shouldn't be unit testing a couple of tightly related methods as one unit. ...


2

While views shouldn't contain business logic, they still can contain basic conditional logic, loops, etc. Since your website is “very heavily based on whether an event has occurred or will occur”, this is definitively a case where you'll have two views, not one. What questions could I ask myself to help me determine the best approach to take to this in ...


1

I've never used Laravel, so I'm not 100% sure this will work for you, but one method I've used in the past is to include either a list or an optional value in my viewmodel that contains the name of another model to render and the data to put there. The view then iterates over the list/checks for presence of the value and includes the appropriate view ...


0

Identifying the pattern. This pattern is actually pretty smart. In fact it's so useful that Microsoft has written a considerable and well liked library called Reactive Extensions to solve this using a technique called functional reactive programming. The pattern you're trying to name is called an Observable. It generalizes an IEnumerable fundamentally. You ...


7

However, the purpose of this is not to be a package manager, but instead a standard to follow when you want to implement a system that silently, automatically updates your software in the background. I'll look through apt and rpm! The problem is that what you want to do is building a package manager whether you like it or not. Your current ...


3

The original poster said: However, the purpose of this is not to be a package manager, but instead a standard to follow when you want to implement a system that silently, automatically updates your software in the background. While you can write an auto-upgrader it is hard to get it right without the package-manager ability to check inter-package ...


3

The core idea would be to find the difference between the set of files currently installed on someone's computer and the newest set of files that should be installed on that person's specific computer; and (once these differences are determined) download whatever new files are missing and discard whatever old files are obsolete; hopefully in an "atomic" way ...


1

If I may rephrase your question, you are asking "what happens to my system if something breaks?" Well, the short answer is that your system no longer functions properly. This happens all the time in complex systems. The degree to which you experience degraded functionality will depend upon what broke and how important it is. For example, when the space ...


1

This is a tricky question :) If I really have to choose from only this two options, I would choose A for the simpler form of your task and B for the extended. That is because events does not really make sense until you are calling exactly one function. The primary responsibility of your nodes is to filter the data that they receive. Still when you change ...


0

In a single application references are easier. Above all, they will allow you to process data asynchronously. If your nodes can be located in different applications (even in different computers) you'll need an event-based pattern like Message Queue. This pattern can be implemented with help of .NET events in each single application. So, if you don't plan ...


4

It depends on the layering of the design. If "nodes" are all in the same layer conceptually, then I would prefer references over events, especially read-only references. References are simpler and easier to trace with static analysis tools: References can be read-only fields, whereas event fields are always mutable. A reference field refers to a single ...


2

In times like this I try to step back, forget the implementation, and focus on the requirements. Essentially, you want to: - Define discrete entities using primitive data elements - Validate entities using domain-specific rules - Construct a domain model from valid entities - Perform useful and interesting computations with your domain model If you're in ...


0

You can potentially mix 1 and 2 but create less work in the process. I would initially build your query logic on the assumption that all requests would be of the form "show all documents published on all websites" and then extend it to support filtering by tags (adding parameters to queries is easier than taking them away). You'd achieve this by simply ...


0

One option is to use a parameter object. Take the parameters required by every instance and bundle them as a seperate class. See also this question


5

The Builder pattern is most useful when the product you are building consists of multiple discrete parts, where external information specifies which parts, or if the product has many optional properties. In your case, you have a long list of required properties. Here the Builder pattern only gives you the appearance of a less complex constructor at the cost ...


2

There is no way to logically group these into different objects to reduce the amount of parameters passed into the constructor. I think this is the essence in your problem. First, the Builder pattern is normally used in this situation as best practice. However, for me personally, I don't like it and even consider it an anti pattern. You in some way ...


3

This looks like a good application of the ideas of "Finite State Machine" and "Polymorphism". You've already defined your states, so the next step is to define the transitions between states, and the behavior of the system when it's in each state. There are many ways to implement state machines, but in this case you might benefit from three classes, one ...


2

Is it just a symptom of my previous classes depending too tightly on each other? Most probably yes. Although you can get similar effects with a rather nice and clean code base when the requirements change enough How can I avoid this kind of cascading refactorings in the future? Apart from stopping to work on legacy code, you can't I'm afraid. But ...


2

The answer by scriptin is giving a reasonable solution, but doesn't answer your questions about the failure of the implementation you had. You get a 'queue empty' error when you call pop on a Ruby queue in non-blocking mode (true passed) and there are no items on the queue. Your "producer" thread is created and your "consumer" thread is created, but ...


-1

I think you usually cannot unless you are willing to keep things as they are. However, when situations like yours, I think the better thing is to inform the team and let them know why there should be some refactoring done in order to continue more healthy development. I wouldn't just go and fix things by myself. I would talk about it during Scrum meetings ...


8

From (the wonderful) book Working Effectively with Legacy Code by Michael Feathers: When you break dependencies in legacy code, you often have to suspend your sense of aesthetics a bit. Some dependencies break cleanly; others end up looking less than ideal from a design point of view. They are like the incision points in surgery: there might be a scar ...


1

This depends on how complex the widget is. You can create and start a widget as long as you pass it all information and dependencies to make it operational. If you have a complex class that relies on many other classes to do specialized work, then you need to instantiate all those helper objects in the constructor function, or pass them in as arguments. This ...



Top 50 recent answers are included