New answers tagged

0

The case described is ideal for using logic programming and graph-based data structures. You have two parts: Relationships in the most basic form (including basic facts like marriages, divorces, births, etc - I believe there are good standard ontologies for those), and rules on how to "call" those relationships. I do not know how constrained is your "client"...


5

This does seem odd, but I guess I can't be surprised these days where everyone thinks in terms of RESTfulness I would expect the client to hide the underlying implementation, not fake expose it. So if a parameter is missing throw a standard ArgumentException or have some custom validation method that you have to call before sending. If the server returns ...


0

And if you were to be working with a system with discriminated unions/algebraic data types, you could pass it in as, say, a TimePeriodSpecification. type TimePeriodSpecification = | DateRange of startDate : DateTime * endDate : DateTime | MonthCount of startDate : DateTime * monthCount : int | MonthlyPayment of startDate : DateTime * ...


1

Just add a query parameter (e.g. modified_after) that the client can use to fetch only items that have changed since the last time. The modification time should be part of the item's data, so the client can just take the youngest modification time of its cached items to select everything new.


1

As an alternative you could also break the responsibility of specifying the number of month and leave it out of your function : getPaymentBreakdown(420, numberOfMonths(3)) getPaymentBreakdown(420, dateRage(a, b)) getPaymentBreakdown(420, paymentAmount(350)) And the getpaymentBreakdown would receive an object which would provide the base number of months ...


-1

Usefullness of null? Very much so when you go with a List of Lists to model a 2D real life plate with different positions. Half of those positions could be empty (in random coordinates) while the filled ones don't represent a simple int or String but are represented by a complex object. If you want to keep the positional info, you need to fill the empty ...


2

Well, in other languages, you'd use named parameters. This can be emulated in Javscript: function getPaymentBreakdown(total, startDate, durationSpec) { ... } getPaymentBreakdown(100, today, {endDate: whatever}); getPaymentBreakdown(100, today, {noOfMonths: 4}); getPaymentBreakdown(100, today, {monthlyPayment: 20});


7

Sometimes fluent-expressions help on this: let payment1 = forTotalAmount(1234) .breakIntoPayments() .byPeriod(months(2)); let payment2 = forTotalAmount(1234) .breakIntoPayments() .byDateRange(saleStart, saleEnd); let monthsDue = forTotalAmount(1234) .calculatePeriod()...


99

Seeing the implementation, it appears to me what you really require here is 3 different functions instead of one: The original one: function getPaymentBreakdown(total, startDate, endDate) The one providing the number of months instead of the end date: function getPaymentBreakdownByNoOfMonths(total, startDate, noOfMonths) and the one providing the ...


20

Additionally I feel it sets a bad precedent and adds responsibilities to the API that it should not concern itself with (i.e. violating SRP). Suppose additional consumers want the function to support more use cases, such as calculating total from the numMonths and monthlyPayment parameters. This function will become more and more complicated over time. You'...


Top 50 recent answers are included