api-design

Default argument vs overloads in C++

爱⌒轻易说出口 提交于 2019-11-27 22:09:37
问题 For example, instead of void shared_ptr::reset() noexcept; template <typename Y> void shared_ptr::reset(Y* ptr); one may think of template <typename Y = T> void shared_ptr::reset(Y* ptr = nullptr); I think performance difference is negligible here, and the second version is more concise. Is there any specific reason the C++ standard goes the first way? The same question has been asked for the Kotlin language, and default argument is preferred there. Update: std::unique_ptr::reset() follows

REST api versioning (only version the representation, not the resource itself)

一个人想着一个人 提交于 2019-11-27 16:55:57
I had a look at Best practices for API versioning? , but am not quite convinced of the answer, so I am question the versioning part again with a more specific example. I am having two URIs (one with versioning as part of the URI and one without): http://xxxx/v1/user/123 -> favored solution in discussed thread http://xxxx/user/123 I am having my doubts whether the first link expresses the idea of REST. I find http://xxxx/v1/user/123 confusing as it suggests that there will be a higher api-version someday like http://xxxx/v2/user/123 . But this does not make sense in REST terms, the api version

Why don't primitive Stream have collect(Collector)?

蹲街弑〆低调 提交于 2019-11-27 12:47:55
问题 I'm writing a library for novice programmers so I'm trying to keep the API as clean as possible. One of the things my Library needs to do is perform some complex computations on a large collection of ints or longs. There are lots of scenarios and business objects that my users need to compute these values from, so I thought the best way would be to use streams to allow users to map business objects to IntStream or LongStream and then compute the computations inside of a collector. However

Do fluent interfaces violate the Law of Demeter?

我是研究僧i 提交于 2019-11-27 10:05:38
问题 The wikipedia article about Law of Demeter says: The law can be stated simply as "use only one dot". However a simple example of a fluent interface may look like this: static void Main(string[] args) { new ZRLabs.Yael.Pipeline("cat.jpg") .Rotate(90) .Watermark("Monkey") .RoundCorners(100, Color.Bisque) .Save("test.png"); } So does this goes together? 回答1: Well, the short definition of the law shortens it too much. The real "law" (in reality advice on good API design) basically says: Only

Call a Server-side Method on a Resource in a RESTful Way

﹥>﹥吖頭↗ 提交于 2019-11-27 09:56:12
Keep in mind I have a rudimentary understanding of REST. Let's say I have this URL: http://api.animals.com/v1/dogs/1/ And now, I want to make the server make the dog bark. Only the server knows how to do this. Let's say I want to have it run on a CRON job that makes the dog bark every 10 minutes for the rest of eternity. What does that call look like? I kind of want to do this: URL request: ACTION http://api.animals.com/v1/dogs/1/ In the request body: {"action":"bark"} Before you get mad at me for making up my own HTTP method, help me out and give me a better idea on how I should invoke a

RESTful design: when to use sub-resources? [closed]

若如初见. 提交于 2019-11-27 09:40:49
问题 When designing resource hierarchies, when should one use sub-resources? I used to believe that when a resource could not exist without another, it should be represented as its sub-resource. I recently ran across this counter-example: An employee is uniquely identifiable across all companies. An employee's access control and life-cycle depend on the company. I modeled this as: /companies/{companyName}/employee/{employeeId} Notice, I don't need to look up the company in order to locate the

Why Java does not allow overriding equals(Object) in an Enum?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 08:48:57
I've noticed that the following snippet... @Override public boolean equals(Object otherObject) { ... } ...is not allowed for an Enum, since the method equals(Object x) is defined as final in Enum . Why is this so? I cannot think of any use case which would require overriding equals(Object) for Enum. I'm just curious to know the reasoning behind this behavior. Anything but return this == other would be counter intuitive and violate the principle of least astonishment . Two enum constants are expected to be equal if and only if they are the same object and the ability to override this behavior

How do you implement the factorial function in C++? [duplicate]

六眼飞鱼酱① 提交于 2019-11-27 05:41:24
问题 Possible Duplicates: Calculating large factorials in C++ Howto compute the factorial of x How do you implement the factorial function in C++? And by this I mean properly implement it using whatever argument checking and error handling logic is appropriate for a general purpose math library in C++. 回答1: Recursive: unsigned int factorial(unsigned int n) { if (n == 0) return 1; return n * factorial(n - 1); } Iterative: unsigned int iter_factorial(unsigned int n) { unsigned int ret = 1; for

When should we create our own Java exception classes? [closed]

寵の児 提交于 2019-11-27 03:57:14
问题 From a good design/practice point of view, when should we create and use custom Java exception classes instead of the ones already predefined in Java? In some applications I see almost custom exception classes created, they make an effort to always use native Java exceptions. On the other hand, there are some applications that define custom exceptions for (almost) everything. 回答1: From Best Practices for Exception Handling: Try not to create new custom exceptions if they do not have useful

What is the standard for formatting currency values in JSON?

只愿长相守 提交于 2019-11-27 03:45:04
问题 Bearing in mind various quirks of the data types, and localization, what is the best way for a web service to communicate monetary values to and from applications? Is there a standard somewhere? My first thought was to simply use the number type. For example "amount": 1234.56 I have seen many arguments about issues with a lack of precision and rounding errors when using floating point data types for monetary calculations--however, we are just transmitting the value, not calculating, so that