api-design

Error handling / error logging in C++ for library/app combo

I've encountered the following problem pattern frequently over the years: I'm writing complex code for a package comprised of a standalone application and also a library version of the core that people can use from inside other apps. Both our own app and presumably ones that users create with the core library are likely to be run both ...

Do fluent interfaces violate the Law of Demeter?

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) ...

Strings or URI in .NET APIs?

I am writing an .NET wrapper API for the Netflix API. At this point I can choose to represent URLs as either strings or URI objects. Seems to me there is a good case for both. So if you were using an API, which would you prefer? ...

How do you define a good or bad API?

Background: I am taking a class at my university called "Software Constraints". In the first lectures we were learning how to build good APIs. A good example we got of a really bad API function is the socket public static void Select(IList checkRead, IList checkWrite, IList checkError, int microseconds); in C#. The function receives 3...

Interesting API Design/Pattern Question

I am re-designing part of our internal ORM tool, and I want to expose Field (a class that represents a field in the database, like CustomerFirstName) directly to the end-developer. So that was easy enough to accomplish, however the API got a little ugly because this Field class was previously used internally and is too open. For instanc...

Windows API and GetClassName()? Another name?

I have some code that has a dynamic-class system in C++ that has a member called GetClassName(), a rather harmless name one would imagine. However when included in a large project with Windows headers all hell broke loose. Apparently Windows uses a #define GetClassName (GetClassNameA or GetClassNameW) which screws up everything, and my v...

What's the point of DSLs / fluent interfaces

I was recently watching a webcast about how to create a fluent DSL and I have to admit, I don't understand the reasons why one would use such an approach (at least for the given example). The webcast presented an image resizing class, that allows you to specify an input-image, resize it and save it to an output-file using the following ...

Prohibit direct extension of Java class outside its package

I have a package with a public abstract class Player { /*...*/ } and these public abstract class GamePlayer extends Player { /*...*/ } public abstract class TournamentPlayer extends Player { /*...*/ } public abstract class StatelessPlayer extends Player { /*...*/ } Users of the package need Players but in order to use the package w...

Can someone summarise visibility choices for Java interfaces?

I have two questions really: 1) When would you use a package-private interface? 2) Is there a way to have a public interface which is closed for implementation outside its package? ...

When is an API overengineered?

I despise working with overengineered APIs that don't make simple things simple. Nonetheless, I'm working on designing an API for an open-source library and I'm starting to feel that I'm falling into the overengineering trap. I really can't tell for sure because, of course, I wrote the darn thing, so how it works is more obvious to me ...

Why is DialogResult a nullable bool in WPF?

Can anyone think of a good explanation for the fact that result of a dialog is a nullable bool in WPF? This has always baffled me. In WinForms it was an enum type and that made a lot more sense to me. ...

What's missing in Cocoa?

If you could add anything to Cocoa, what would it be? Are there any features, major or minor, that you would say are missing in Cocoa. Perhaps there is a wheel you have had to invent over and over because of an omission in the frameworks? ...

When do I define objective-c methods?

I'm learning Objective-C, and have a C/C++ background. In object-oriented C++, you always need to declare your method before you define (implement) it, even if it is declared in the parent class. In procedural-style C, IIRC, you can get away with just defining a function so long as it is only called from something else in the same ...

Naming a dictionary structure that stores keys in a predictable order?

Note: Although my particular context is Objective-C, my question actually transcends programming language choice. Also, I tagged it as "subjective" since someone is bound to complain otherwise, but I personally think it's almost entirely objective. Also, I'm aware of this related SO question, but since this was a bigger issue, I thoug...

Static factory method gateway to internal factory - code smell?

Say I had a class that has a static factory method, like this: public class Table { public static Table OpenTable(string path) { ITableFactory fac = IoC.Resolve<ITableFactory>(); return fac.OpenTable(path); } } and a factory class that looks like this: internal class TableFactory : ITableFactory { i...

Asking for opinion for my MenuTree structure. Which is better, array or delimiter approach?

Which is the better API? I think the latter approach is better because strings are interned. But I'm pining for succintness. Which do you think is better? [Task("Assortment", Author = "好先生", MenuTree = "The>Quick>Brown>Megan")] public partial class Form1 : MycForm, ITaskPlugin { } or this(strings can be interned): [Task("As...

Hiding Complexity by Building Concise Libraries

I'm developing a product with a bunch of interlocking pieces (server, client, libraries, etc) and one of the pieces is a tiny library that users will link into their own client-side code (something kind of like the Flickr API or the Google Maps API). Once they've included that library, all of the interlocking bits magically hook themselv...

Why is the Java date API (java.util.Date, .Calendar) such a mess?

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar) are a terrible mess. Off the top of my head: Date is mutable Date represents a timestamp, not a date no easy way to convert between date components (day, month, year...) and Date Calen...

Generic methods for checking if a library/API is thread safe

I received a library from an external developer in form of a well defined API(in C++ and Java). What can be some tests to check if the library is thread-safe ? ...

Best API for modeling networked devices with arbitrary attributes to learn from?

I need to design a new API which models networked devices which have a large amount of attributes which vary quite a lot based on the device's type. The attribute set is not totally arbitrary though, it is a big set of known attributes. That said, with new devices come new attributes so the situation is never totally fixed. The network...