New answers tagged

0

What you need is a leader (or supervisor) who understands software development, and who makes the decision about which approach should be used in the project. If necessary, the leader directs the developers to work in a particular way, irrespective of their personal preferences.


1

Obviously they are both wrong. The bottom up guy is hacking away at code and will never produce something that does what it is supposed to do - it'll be a continual churn as the unknown requirements are determined. The top down guy can spend just as long on architectural vision and get nothing productive done too. However, a middle ground is ideal - if ...


0

This actually sounds like an ideal scenario to me. Then again, I am both of those developers at the same time. I like to draft out the "big picture" in the form of notes that eventually find their way into an issue tracker. Then I start thinking about the implementation details from the bottom up. The big picture evolves as I gain a better understanding ...


4

The two developers need to maintain a mutual respect for each other. The top down person needs to respect the fact that the bottom up person may have come up with something that actually works. As one of my "quant" professors told me, "A working model is worth 1000 guesses." If that's the case, the top down person should consider re-doing his "design" to ...


1

You can minimize the loss of time spent by each developer if you break apart large tasks into multiple smaller and more focused ones. Have them work closely together so that neither of them get too far ahead of the other. Short sprints, and small deliverables go a long way. It's easier to fix a small mistake than a big one. It might seem counter ...


0

When you add a new column to a database table, you will usually either give the column a default or update the current rows in the same script. You're sort of doing the same thing here, just with the extra indirection of having a serialized string instead of a table, it's a little trickier. Many SQL implementations have tools for parsing and writing XML, so ...


2

Function contract comments should be in javadoc comments rather than plain comments (i.e. comments beginning with /**). Many syntax-highlighting editors are able to highlight these with a different colour to other comments (e.g. eclipse). File history/copyright/licence comments should be confined to the top of the file. Work-in-progress/task-related ...


1

In just about any programming language, you can pass some type of list, array, tuple, record, or object as the only argument. It's only purpose is to hold other items instead of passing them to a function individually. Some Java IDE's even have an "Extract Parameter Object" feature to do just that. Internally, Java implements variable numbers of arguments ...


7

You could try creating Custom JavaDoc Tags. Your design decisions could have an @why tag or something. I've always thought comments that answer the question "Why?" tend to be the most useful. That said, I agree with @JohnBode and @BobDalgleish that you don't want to paste pages of your design docs into your code, but an abbridged "TL;DR" summary of those ...


3

Why nested classes ? Bjarne Stroustrup explains in "The design and evolution of C++", the origin and rationale behind nested classes: original C++ in 1984 had a single name space (page 5 and 102). the use of nested classes was a compromise between the the concept of a class as a scope and the need of compatibility with C (page 102) it was further ...


0

There may be another solution than one proposed by Ewan, though his is excellent. Suppose you have a pool of queues. At any moment, a queue is either free (not being used at all) or assigned to a specific bank account. You still need a master worker to allocate a queue for use, assign it to a bank account, and make it available to the next free subordinate ...


1

So, You have two issues here 1: Prevent/Resolve Simultaneous actions (withdrawals) on a single resource (bank account) 2: Enforce processing actions (withdrawals) in a particular order In your example, you could resolve 1 in a number of ways, but lets take the simplest. Processing the withdrawal calls ReduceBalance(accountId, amount) on some bank account ...


0

I think there is 2 factors that can make you choose between one or the other Is "Manage" a classical CRUD case or is there more ? Is the whole diagram already quite big ? Now ideally depending on the result of the two questions : If yes for the first -> go for "manage" If no for the 1st and yes for the 2nd, go for "manage" and add another diagram ...


1

The guiding principle at work here is probably "if you ever need to run a query on the data, and not just display it in its native form, then the data needs to be first-class rows and columns, not some JSON stuffed into a single field."


1

I think you've done a great job in decoupling the dependencies, what I could suggest here is to not return already SortedDataQueue object from DataLoader since it's responsibility is only to retrieve data. In that case, you can create the class: class DataCollector { SortedDataQueue collectIntoQueue(); DataCollector init(Array<Data&...


5

Polymorphism with no shared interface will ONLY let you store objects in the same (strongly typed) container, not actually DO anything. You can't disptach method calls or anything like that. In your specific example, I think composition would be more appropriate, no? You already have an abstraction for a specific point in 2d space, so why woudn't you reuse ...


2

The two subclasses does not have any interface in common, so why you do you want to have them inherit from a common class in the first place? The Location class does not provide you any benefit as far as I can tell. To me it would seem to more logical to have the Line contain two Point's.


0

The answer to this depends 100% on who is going to read your code. What styles do they find most helpful? I have found the most general case is that one avoids reassigning values to function arguments because too many developers have mental models of how function calling works which assume that you never do this. This problem can be exacerbated by ...


4

A language based around how it constrains the developer is dependent on the assumption that the language developer understands the needs of each programmer better than the programmer understands those needs themselves. There are cases where this is actually valid. For example, the constraints on multithreaded programming requiring synchronization using ...


2

Are they a smell? No, they're not. They make our code better by separating the responsibilities of creating an object and of using it. I don't know if your language has the concept of "using" a resource, then automatically disposing of a resource, but it can hamper testability. Consider the following code from a service implementation. public ...


1

I think you alluded to the answer of when it's bad: these kinds of factories usually don't do runtime decision making In my opinion, factories should generally only be used when you don't know at compile time what you need to be creating. While the factory example you gave might actually serve a useful purpose in whatever context its being used for, I ...


0

Instead of checking and invoking specific makeComboBox vs. makeNumericTextField, consider invoking a generic constructUI, which would be a virtual method on the base class FormElement that is overridden by the various subclasses, each of which does the equivalent. The idea behind OOP is to instruct the object to do something useful on its own and return to ...


5

The purpose of the factory pattern is to provide an abstraction between object creation and code that needs to create objects. There are many reasons why this may be desirable: Objects might be able to be pooled, and a factory can manage the pool. This is what Java's Integer.valueOf(int) does. Objects might have tricky constructors to use. This is often a ...


2

I don't think what you are showing in the sample is bad, but there are some alternatives. You can create a type that represents the car kind, for example, minimally enum CarKind { Default, Fancy }; Then have a simple constructor in Car that take the CarKind, so clients do new Car ( CarKind.Default ) instead of CarFactory.createDefault (). The ...


1

the classic way is to use a Factory class with your switch Factory.Create(data) { switch data.class case : combo return new Combo(data) .... } this can be made more generic using reflection until you end up with a dependency injection container container.Register<FormElement,Combo>().Named("combo") container.Resolve<...


-2

I have a completely diffrent problem with your code example: Your method's name is SanitizeName. In this case, I expect it to sanitize a name; because that is, what you tell the reader of your function. The only thing, which you function should do, is sanitizing a given name. Without reading your code, I would expect the following: string SanitizeName(...


0

If you use a static code analyzer for security purposes, it may get confused, and think you haven't validated or sanitized the input parameter variable prior to use. If you use Name in a SQL query, for example, it might claim a SQL injection vulnerability, which would cost you time in explaining away. That is bad. On the other hand, using a distinctly named ...


7

I've been spending some time these last few weeks attempting to learn the J computer language. In J, pretty much everything is an operator, so you only get "monads" (functions that have only one argument) and "dyads" (functions with exactly two arguments). If you need to more arguments, you have to either provide them in an array, or provide them in "boxes"...


1

You will need two things: Closure Composite data type I will add a mathematical example to explain the answer written by J├Ârg W Mittag. Consider the Gaussian function. A Gaussian function has two parameters for its shape, namely the mean (center position of the curve) and the variance (related to the pulse width of the curve). In addition to the two ...


8

I think it depends on your coding conventions in your project. I personally let eclipse automatically add the final keyword to every variable and parameter. This way you see at the first glance if a parameter is reused. In the project at my job we do not recommend to reuse parameters, but if you just want to call e.g. .trim() or set a default in a null ...


43

There are lots of languages which already work this way, e.g. Haskell. In Haskell, every function takes exactly one argument and returns exactly one value. It is always possible to replace a function that takes n arguments with a function that takes n-1 arguments and returns a function that takes the ultimate argument. Applying this recursively, it is ...


38

Robert C. Martin in his book "Clean Code" recommends heavily the use of functions with 0, 1 or 2 parameters at maximum, so at least there is one experienced book author who thinks code becomes cleaner by using this style (however, he is surely not the ultimative authority here, and his opinions are debatable). Where Bob Martin is IMHO correct is that ...


1

I think you are confusing Minor version and Patch version. From http://semver.org/ : Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes. This leads ...


0

If I were you I'd start by utilising the "M" in MVC and abandoning the ViewBag: start creating view models. If you begin by creating a model for your grid sorting, filtering and paging you'll start see where the common functionality is and isn't, i.e. what is specific to a given grid and what is general. You don't have to go to the Repository pattern in ...


0

Sounds like a state machine to me. Create a set of events and have the end of one start the beginning of the next one. The line growing would be a state (with state of its own representing the current length), then the full length line (maybe pulsating or something) would be another state. Then, maybe an event would then trigger a "close" even where the ...


0

When you call an API through https, you can get the following answers: Internet is down. Cannot connect to the server. https failed to negotiate (after reaching the server). A nonsense answer when you use http in a Starbucks. The server tells you that the API is currently down. The API tells you that it isn't working right now. The API gives one of many ...


0

I don't think there is a definite right answer. It depends of course. If I were you I would think about what the ideal user experience would be when this happens. Then do whatever it takes in your application to make that happen. You could just throw an error and tell the user to try again later. Or if it's an issue that happens sporadically, just retry the ...


0

If you can't rely on the 3rd party API to give you a response (and you're accessing it synchronously) you can set a time-out. I would access the 3rd-party API on a separate thread (or even process) and wait for the response with a time-out set. If the time-out expires, just move on. Additionally, I had a very similar problem a while back. Feel free to check ...


0

If you're giving flow of control to the API the response is to wait until hell freezes over, or the user presses ctrl-alt-del. If you're calling it asynchronously the typical strategy is to timeout. If the API throws an exception, easy: clean up, log, and display the error. Whatever you do, don't fail quietly. I hate debugging things that fail quietly. ...


4

I think a very maintainable way would be to define functions that take a tweet and return a boolean like this: def has_terms(*terms): return lambda tweet: any(term in tweet['text'] for term in terms) def complex_rule(tweet): return 'boo' in tweet['text'] and not any(y in tweet['text'] for y in no_words) Then you can set up your list of rules ...


2

Let's look at this in a more general way: Is creating drafts a good idea? Who should create the drafts? Is creating drafts a good idea? Creating drafts mainly provides 2 benefits. First, it provides focus, which leads to a speedup in the actual work being done. Second, it makes discussing the direction of the work before the work is complete so much ...


2

ALWAYS! I work for a small company, and I am the only "Soft" IT person. I do all requirements, design, coding, testing (though someone always validates my testing), database design etc. NEVER CUT CORNERS ON THE DESIGN STEPS - your end users will thank you. You will thank yourself too, because you WILL end up re-working it to make the end users happy. ...


1

Your first approach look good. Clan/character is a container relashionship and so the ideal approach would be the Clan has a list of members, and the character is unaware of Clan class. That means character's API must be designed so Clan can implement its services.


-2

Your collegue is absolutely correct. Internal applications generally have a predefined look. Also for such applications, users are not looking for cutting-edge UI. All they want is something that works and is reasonably easy to use. Unless you plan to radically change the UI(which I will strongly advise against....for internal apps), just follow the existing ...


5

Not necessarily. There are at least two reasons why mockups might be of little use. First, if there are well-established industry practices regarding doing the things you are about to be doing, you can just go ahead and do exactly that. You won't be pushing forward the art of UI design, but that is just as well. Second, your end users often don't know what ...


0

Perhaps you could have something like this? @service('some-service-name') def action(client, data): # action endpoint do_stuff() return @service('some-service-name') def connect(): pass @service('some-service-name') def disconnect(): pass The 'service' decorator takes a single argument, which is the service name. You could use the '...


0

Most of the time, it doesn't need to know; aggregates with correctly designed boundaries don't need to know about outside state to maintain its invariant (that's basically the definition of an aggregate boundary). When an aggregate needs to know about state outside it's own boundary, the usual answer is a DomainService. The aggregate invokes a query on the ...


11

Yes, absolutely. Don't let someone else tell you how to do your job. And you are right, it's very much like doing UML for your data model. Assuming you are a developer, your job is to deliver quality software. If mockups help you do that, then that's part of your job. Do low fidelity mockups -- don't make them look like real screens. You'll waste too much ...


39

Mockups are fantastic and there is no reason a dev shouldn't do them. (It can even be handy for a dev to do a rough draft of a UI layout even when you have UI designers on the project.) I highly recomend you don't make mockups that look like actual screens. If you share these with end users that often focus on things that don't matter like colors and ...


10

When designing "a new screen", you want to discuss the rough idea of the UI first with a user and/or your colleagues. You cannot discuss this with a user "in code" or "in UML", that simply does not work (it won't even work between programmers). And you should expect that you need to throw away your first two or three scetches, or at least rearrange the UI ...



Top 50 recent answers are included