Category: Designing Contracts
-
Wenn ein Rezept nach Heimat klingt: Mundart in alten Familiennotizen
Auf einer vergilbten Karte steht „a Schuss Milch“, daneben eine Zutatenliste in krakeliger Schrift. Wer das Rezept heute nachkochen will, versteht vielleicht jedes Wort und stolpert trotzdem über den Ton: Wie viel ist ein „Schuss“? Und meint die Großmutter damit tatsächlich eine bestimmte Menge oder eher eine großzügige Handbewegung? Familienrezepte bewahren nicht nur Mengenangaben. Sie…
-
Der gute Termin beginnt vor der Haustür: So planen Sie einen Besuch in Hürth
Ein Termin vor Ort scheitert selten an einer großen Sache. Häufig kostet eine fehlende Unterlage Zeit, die Anfahrt dauert länger als gedacht oder eine wichtige Frage fällt erst ein, wenn man schon wieder zu Hause ist. Mit wenigen Minuten Vorbereitung lässt sich vieles davon vermeiden, ohne den Besuch bis ins Kleinste durchzuplanen. Der erste Schritt…
-
Een Uitgebreide Kijk op de Voordelen van HolyLuck Casino voor Vastere Winsten en Veilig Spelen
Waarom Kiezen Voor HolyLuck Casino? HolyLuck Casino heeft zich gepositioneerd als een must-try platform voor spelers in Nederland en andere delen van de EU. Het casino biedt een breed scala aan spellen, aantrekkelijke bonussen, en een veilige speelomgeving die voldoet aan strikte Europese normen. Of je nu een fan bent van gokkasten, tafelspellen of live…
-
Tooling support
There is more and more support for pre- and post-condition checks, even in languages like Java. For instance, IntelliJ, a famous Java IDE, offers the @Nullable and @NotNull annotations. You can annotate your methods, attributes, or return values with them, and IntelliJ will alert you about possible violations. IntelliJ can even transform those annotations into proper assert checks at compile time. In addition,…
-
Should we write tests for pre-conditions, post-conditions, and invariants?
In a way, assertions, pre-conditions, post-conditions, and invariant checks test the production code from the inside. Do we also need to write (unit) tests for them? To answer this question, let me again discuss the difference between validation and pre-conditions. Validation is what you do to ensure that the data is valid. Pre-conditions explicitly state…
-
When not to use design-by-contract
Understanding when not to use a practice is as important as knowing when to use it. In this case, I may disappoint you, as I cannot see a single good reason not to use the design-by-contract ideas presented. The development of object-oriented systems is all about ensuring that objects can communicate and collaborate properly. Experience…
-
Exception or soft return values?
We saw that a possible way to simplify clients’ lives is to make your method return a “soft value” instead of throwing an exception. Go back to listing 4.5 for an example. My rule of thumb is the following:
-
Asserts and exceptions: When to use one or the other
Java does not offer a clear mechanism for expressing code contracts. Only a few popular programming languages do, such as F#. The assert keyword in Java is okay, but if you forget to enable it in the runtime, the contracts may not be checked in production. That is why many developers prefer to use (checked or unchecked)…
-
Input validation, contracts, or both?
Developers are aware of how important input validation is. A mistake in the validation may lead to security vulnerabilities. Therefore, developers often handle input validation whenever data comes from the end user. Consider a web application that stores products for an online store. To add a new product, a user must pass a name, a…
-
Weak or strong pre-conditions?
A very important design decision when modeling contracts is whether to use strong or weak contracts. This is a matter of trade-offs. Consider a method with a weak pre-condition. For example, the method accepts any input value, including null. This method is easy for clients to use for the clients: any call to it will…