Tag Info

New answers tagged

0

This depends a great deal on the nature of the PDFs you accept as input. If you have control over the format of the PDF you're accepting, you can very easily extract the data you need; on the other hand, if you agree to accept any valid PDF at all, your task will be much harder. A loose hierarchy of options that PDFs can provide: PDF forms are designed ...


0

Calculate the distances between zip codes once and cache them. Keep the restaurants list sorted by the distance to the user. Enumerating the restaurants starting from the smallest distance you can detect the point when the restaurants go out of walking range - at that point you can ignore the rest and break the loop.


0

The API should do whatever it can to give the application the necessary information how to proceed. But for the user, the message is most likely: None - for things like updates, prefetch etc. or where retrying helps. Tell them "it didn't work". Tell them "it didn't work, it might work later". Tell them "it didn't work, here's what you can do to fix it" ...


0

Based on some back-of-the-envelope thinking, I would suggest the following approach: If you sum each individual row, each column, each diagonal, and the 4 corners, you will obtain a set of 9 numbers, which can then be sorted. This sorted list of numbers will be identical for all the cases you listed and their rotations, but should be unique (i.e., not ...


1

Calculate a hash value for each of the eight symmetric matrixes and keep only the smallest of them - that should do the trick. This gives you the same value for each matrix of an equivalence class.


4

You've discovered the need for spatial indexing. R-trees are probably the most common approach. The basic idea is a tree structure with rectangular bounding boxes computed over all the children of a given node. That way searching for a region or a point can traverse the tree, pruning out any parts of the tree (most of it) where the bounding box is not a ...


0

You can use mathematics to identify similarity. I have assumed each example you have given after the initial matrix for similarity as condition. For the matrix in your example - Let Ux = 1 2 3 4 5 6 7 8 9 Let Ix = 0 0 1 0 1 0 1 0 0 If you perform the matrix multiplication of Ux and Ix you would obtain - Ux . Ix = 3 ...


0

Instead of storing one hash value, store 5 hash values M0= 1 2 3 4 5 6 7 8 9 is identified as the same as all the following matrices Operations which creates M1 to M4 are written below M1= 3 2 1 (vertical mirror M1:= VM(M0) ) 6 5 4 9 8 7 ----- M2= 7 8 9 (horizontal mirror M2:= HM(M0) ) 4 5 6 1 2 3 ----- M3= 1 4 7 (transpose ...


2

No, a builder is not unheard of for building messages. Spring Integration does something similar with a Builder. Spring Integration messages have a general structure like yours: a payload and a header. There's the Message interface public interface Message<T> { T getPayLoad(); MessageHeaders getHeaders(); } The MessageHeaders class (your ...


0

Hopefully this doesn't sound too harsh, but neither solution is very scalable or performant. Unlike a lot of other answers I actually prefer your solution over his for what its worth! This is going to be totally dependent on your specific needs, but if you only care if the user has received the LATEST newsletter, you could give a unique auto incrementing ...


5

Even though you said algebraic data types, you seem to mostly be asking about sum types, so I will focus on those. Product types are more common and more easily understood. Sum types are most easily understood not by thinking about what you're modeling, but by thinking about the code that uses it. People tend to think of sum types as representing states ...


4

You need to understand that DDD is not about primary keys, rows or tables - these are just means to implement it. Aggregate root is usually implemented as a class, because you are expected to access all the functionality and data of the aggregate through the root. It therefore needs to have some behavior, something which primary key of the table can't have. ...


0

Trello is good as a kind of software version of a Kanban board, it can be helpful for single person projects but you get most of the benefit from it when you have a team of developers, managers, etc. working on a single project. Working in a profession context I would say even on your own you need to be using at the very least: Source control I would ...


3

First of all, this is not a "problem" which needs "modelling". This is just a syntax issue. Secondly, why on earth would you even think of using a builder pattern for this? Is it perhaps because you read "Clean Code", where on page 35 the author classifies methods into four categories, depending on whether they accept zero, one, two, or the incredibly ...


1

In addition to the other drawbacks that other answers have posited, another is that the Throwable mechanism is designed to be overbearing i.e., it short-circuits normal processing wherever present. Imagine the following public void doSomething(){ Foo it = new Foo(); Bar something = it.doesSomething(); //anything thrown here will cause a hard stop ...


2

If Employee is an aggregate root, it means that all the outside objects can reference only the Employee (and not the ActiveEmployee/InactiveEmployee). Any references from outside the aggregate should only go to the aggregate root. DDD aggregate by Martin Fowler I don't think that's your intent. I think ActiveEmployee and InactiveEmployee are both ...


1

Would it be abusive to create an event system that uses try-catch statements and throwables, which are really made for error handling? Abusive is an emotionally loaded term. And it is blatantly subjective ... unless you are measuring a standard that everyone concerned can agree is applicable. What could that standard be? It could be a particular ...


3

I don't understand how would something like that work. After a method throws an exception, it stops executing and permanently gives up control to some exception handler. But after a method raises an event, it gives up control to the event handler only temporarily, and then continues executing. I don't see how could you emulate temporarily giving up control ...


3

Do you know of guidelines and best practices that guide through modelling logic in types properly? Sure, at least in theory. Algebraic Data Types are made of two parts, sum types (or variants, or discriminated unions, or...) and product types (or tuples; conceptually records and classes fall here, but some disagree). Product Types are used when you ...


6

Having a separate business tier needs justification as it involves lots more work and costs more in performance (see: MS-Business Layer). According to one definition of Web Services, a Web Service is not generally required unless you are communicating between different physical tiers. Accordingly, a DLL may fit best for what you describe. It is common to use ...


4

If your entire stack is .net there is not much value to creating web services. Just reference the DLLs in the .net components that need them, it will be faster as there is no serialization or extra network hop involved. However, for cross platform purposes, web services are the way to go. Then you can have a .net client (ASP MVC app), java client, native ...


1

That is a great question and an interesting problem. I propose that you use a combination of Chain of Responsibility and Double Dispatch patterns (pattern examples here). First lets define the task hierarchy. Notice that there are now multiple run methods to implement the Double Dispatch. public abstract class RecurringTask { public abstract boolean ...


3

I would say Option 1 is the best route to take. The reason you should not dismiss it is that the SendEmailTask is not an entity. An entity is an object concerned with holding data and state. Your class has very little of that. In fact, it is not an entity, but it holds an entity: the Email object you are storing. That means that Email should not take a ...


2

A lot of questions of this kind depend heavily on the actual business domain, and it's not clear that we have enough information to make a good decision. any rebind is treated as non-normal situation This comment suggests that it may make the most sense to send back a error response (e.g. 400 Bad Request) with a description of the reason you're not ...


1

The scenario you describe assumes that when the software is re-installed on a device, that your system will recognize that device as having been seen before. This will only happen if, as part of the registration, the device must send some hardware identification. If you don't use such pre-existing hardware identifications, but you assign an ID after ...


0

I completely disagree with that article. Services (concretely their "API") are important party of the Business Domain and as such will exist within Domain Model. And there is no problem with entities in business domain referencing something else in same business domain. When X send mail to Y. Is a business rule. And to do that, service that sends mail ...


3

Have you had a look at existing libraries e.g. spring quartz or spring batch (I'm not sure what fits your needs most)? To your question: I assume the problem is, that you want to persist some metadata to the task in a polymorphic way, so an e-mail task has e-mail addresses assigned, a log-task a log-level, and so on. You can store a list of those in memory ...


1

I've been developing extensible software for a long time now. I've also been on the other side. One thing I've learned is that you want libraries you use to "Fail fast". What that means is, it should break my software as soon as possible if something is wrong. If you can (which in this case I presume you can't) break at compile time. If not, throw an ...


-2

Dependency injection relies on interfaces. Heres a short example. Class Student has a function called CreateStudent that requires a parameter that implements interface "IReporting" (with a ReportAction method). After it creates a student it calls ReportAction on the concrete class parameter. If the system is set up to send an email after creating a student ...


2

Validation of input parameters/data should be performed whenever the data can come from an untrusted source. To be on the safe side, if anyone outside the development team can supply data to an interface, then that interface should validate its inputs. The more interesting part of the question is what to do when the validation finds a problem. First of ...


2

This sort of problem is well-suited to dynamic typing. That will give you the most straightforward solution, with the obvious trade offs. If you wish to use static typing, you'll have better luck if you don't centralize your pipeline construction. Your stages are the ones who know the most about the types of their dependencies and results, so you should ...


-2

You might be able to model this using a workflow engine. You can model each of your stage as a workflow step and also parameterize each step. Depending on the engine chosen, manual action can be configured against each step. The following post might help you decide if it is relevant to your use case: ...


0

What type of problem are you trying to solve? Are all the 100000 records related to each other so that everything needs to be loaded in memory. If not, try to find a suitable grouping (e.g., customer). Reformulate the problem that handles each group separately and after that group of records are processed, flush the data to the CSV file and clear the memory ...


6

Architect the system so that the algorithms aren't deployed to a machine that an attacker controls. Generally, this will involve hosting the component that implements the algorithms on a server you control and using the client to simply gather input and display the output of the server component. But you could also build the entire thing as a web ...


1

It is perfectly fine, as long as the class hierarchy on which you are doing this is small, self-contained, and not liable to be extended by someone who is not at liberty to refactor it. The visitor pattern is not a bad idea, but it is a hassle to implement, and more importantly, every time you try to read it, you are forced to read a lot of code. Compare ...


-2

I know it's an oldish question, but check out ReactiveX if you haven't already. I discovered it recently, and it's really changed how I see designs like these. It's basically a combination of type-safe observables, event-based push (sync or async), and classic pipes-and-filters. http://reactivex.io/ You just write little components and snap them together ...


0

No, this is not idiomatic. If you absolutely must cast from base type to derived type, use the RTTI mechanism provided by the language. But first, question why you want to do that at all! In most instances you shouldn't need to care what the type of the object is, you should be calling virtual member functions that the derived type implements to do the ...


7

Whenever you feel an urge to inspect the dynamic type of your polymorphic objects at run-time, you should question your design. This is true for any object-oriented language I know. The visitor pattern can be of great help in avoiding to bother with the dynamic type of an object. Some people seem to think that cheating around type inspection by adding a ...


0

You seem to be asking for two different things here: changing the values of some fields Are you referring to how you need to normalize values' formattings ("yyyy-MM-dd" to "ddMMyy") or possibly even data types here (BigDecimal to int)? If so, I'll suggest creating a conversion class to handles these, so that you can safely eliminate both the ...


1

You could have a factory which provides the correct adapted object. Exposing a series of classes or a single class with multiple methods assumes that you have some knowledge before hand of the system. Another (problematic, I think) issue is that by exposing all the adapters you are giving the caller (client) complete control over which adapter gets called. ...


0

Being a mobile developer myself, the worst thing is offline access. You simply force users to be online which should work in a lot of apps, but not in all. The other great bad aspect is slowness. Time needed to parse remote data can take significant time. Yes, you can pre-fetch data during the load time, but in all other cases you cannot avoid slowness. ...


4

The test to apply is whether or not someone can definitively understand the intent of the arguments just by looking at them. In your example, the interpretation of --opt=foo would vary depending on the program's surroundings. That could sow confusion or, worse, cause a security problem if there's a file named foo in the current working directory and the ...


4

Which class should know how to convert a new A to a legacy A? Maybe it's the A class itself which has this knowledge. It may know how new and legacy values are mapped, which fields should be added or removed, etc. In this case the following approach seems quite natural: A legacyA = a.toLegacy(); The benefit of this approach is consistency: it's similar ...


2

You've seen programs that interpret option arguments both as a filename and as literals? Depending on what, the state of the file system? That's an insidious defect or exploit waiting to happen. Never, never, ever do this.


0

Sending data over the wire to an API Is, I think, one of the key drivers of an ADM/POCO style approach to programming (see my question : OOP vs ADM Comparisom where i touch on some of the same points) If you take the OOP route, you are faced with the problems of serializing a model which jealously guards its data and then creating a similar model on the ...


0

Depends on the audience! As developers we developed an intuition for good and bad code, and use vague emotional terms like "code smell", "ugly code", "beautiful solution". This only works when communicating with other developers with the same mindset. Try to explain your non-technical CEO that you should invest x man-hours into making some code "more ...


-2

If your problem is only the warnings of IDE, you can avoid it using 2 solutions solution 1, meta class class ABCMeta(): def func_2(self): return 1 #any valid value, just to your IDE dont complain class MyClass1(ABCMeta): def func_1(self): return self.func_2() * 2 class MyClass5(MyClass1): def func_2(self): return ...


0

I have done both of these approaches in the past and I tend towards the simplified POJOs. The main reason is, it allows and forces in that the business logic is actually performed on the server. When we used to send the full rich model to the client our client code started accumulating little bits and pieces of business logic everywhere and got rather ...


1

One option is to make it clear to the IDE and your users that there is a method, but you can't use the base class version: class MyClass1(object): def func_2(self): raise NotImplementedError def func_1(self): return self.func_2() * 2 You won't get warnings from intermediate classes that don't define func_2, but will get an error ...


5

If func_2 in MyClass1 doesn't contain any logic and is expected to be declared by child classes (and MyClass1 is never used directly), then making the class abstract like you did is a reasonable approach and makes the code self-documenting and explicit. If: func_2 in MyClass1 contains logic (eventually overwritten in child classes), Or MyClass1 may be ...



Top 50 recent answers are included