background preloader

CleanCode

Facebook Twitter

Command-Query-Separation. Object oriented - Why do we need private variables? - Software Engineering Stack Exchange. As stated by others, private variables are good to avoid miss-usages leading the object into an inconsistent status and hard to track bugs and unforeseen exceptions.

object oriented - Why do we need private variables? - Software Engineering Stack Exchange

But in the other hand, what has been mostly ignored by the others is about protected fields. An extended sub-class will have full access to protected fields, making the object as fragile as if such fields were public, but that fragility is limited to the extending class it-self (unless it exposed such fields even more). So, public fields are hard to be considered good, and to the date the only reason to use them is for classes used as configuration parameter (a very simple class with many fields and no logic, so that class is passed as a parameter alone to some method). But in the other hand, private fields lowers the flexibility of your code to other users. Flexibility vs Troubles, pros and cons: Objects instantiated by your code in the vanilla class with protected fields are safe and are your sole responsibility. Design patterns - Naming Classes - How to avoid calling everything a "<WhatEver>Manager"? Prinzipien der Softwaretechnik: Das Gesetz von Demeter.

Das Gesetz von Demeter (engl.

Prinzipien der Softwaretechnik: Das Gesetz von Demeter

Law of Demeter, LoD) gehört heute zur Allgemeinbildung des Informatikers. Seine "Entdecker", Karl J. Lieberherr und Ian M. Holland, waren aus heutiger Sicht erstaunlich euphorisch über seine Bedeutsamkeit: "Wann weist ein objektorientiertes Programm guten Stil auf? Mehr als 20 Jahre später darf geschmunzelt werden. Die Anomalie kann auch auf hörerer Ebene verdeutlicht werden: Struktur und Verhalten sind wesentliche Aspekte jeder Software. Mit dem LoD glaubte Lieberherr einige Jahre später eine Lösung für diese Probleme gefunden zu haben. Katalogeintrag Quellen[Berens2011] - Ein Refaktorisierungswerkzeug zur Umsetzung des Law of Demeter, Masterarbeit, Dietmar Berens (2011)[Knoernschild2001] - Java Design: Objects, UML, and Process, Knoernschild, Kirk (2001) [Lieberherr1988] - Object-oriented programming: an objective sense of style.

Principle of Least Surprise. Das Principle of Least Surprise (deutsch Prinzip der geringsten Überraschung), auch unter der Abkürzung POLS bekannt, ist eine goldene Regel in der Software-Ergonomie, der Mensch-Computer-Interaktion und dem Interfacedesign.

Principle of Least Surprise

Diese Regel wurde von Geoffrey James in seinem Buch The Tao of Programming als Law of Least Astonishment formuliert (Absatz 4.1). Sie besagt, dass eine Benutzerschnittstelle so ausgelegt werden sollte, dass der Benutzer möglichst wenige Überraschungen erlebt. Allgemein kann man somit folgende Regel formulieren: “Never surprise the user!” „Überrasche niemals den Benutzer! Anwendung auf Quellcode[Bearbeiten | Quelltext bearbeiten] Beispiele: Customer GetCustomer(int customerId) Gibt einen Kunden anhand einer eindeutigen Identifikationsnummer zurück.

Customer GetCustomerOrNull(int customerId) Gibt einen Kunden anhand einer eindeutigen Identifikationsnummer zurück. Clean Code - entwickler.de. Die Clean-Code-Prinzipien beschreiben gute Strukturen tendenziell auf Quellcode-Ebene, während Architektur eher größere Strukturen im Blick hat.

Clean Code - entwickler.de

Das gemeinsame Ziel ist es, kontinuierlich für lose Kopplung und verstehbare Strukturen zu sorgen bzw. sie wieder herzustellen. Clean Code ist aber mehr als nur eine Sammlung von Entwurfsmustern – es beschreibt eine Haltung und eine eigene Bewegung. Dave Thomas und Andy Hunt [1] nennen sie das „Broken Window Syndrome“ im Zusammenhang mit verrottender Software.

In ihrem Buch geben sie Entwicklern den guten Rat: „Don’t live with broken windows! “ – übersetzt in unsere Domäne also nicht mit schlechten Designs, falschen Entscheidungen, oder miesem Code zu leben, sondern dagegen vorzugehen. Robert Martin hat mit seinem Buch „Clean Code“ einen gewissen Standard geschaffen und beschreibt viele Hinweise zur Strukturierung des Code. Elementare Sauberkeit durch sinnvolle Bezeichner Elementare Sauberkeit durch verständliche Funktionen zu manipulieren. Fazit. Clean Code with Kotlin. With Kotlin we can write code that is easy to understand, short, expressive and safe.

Clean Code with Kotlin

Sounds like clean code, doesn’t it? In this post, I go through some recommendations and principles of clean code and consider if Kotlin can help to fulfill this rules or not. Moreover, I show restrictions and points, where we should be careful. At the end, I discuss if Kotlin leads to “a dark or a bright path”.

This post bases on my talk “Cleaner Code With Kotlin” (German) which I’ve given at the Clean Code Days in Munich in June 2017. Before we start, it’s important to recap what clean code is. Let’s consider some rules and recommendations of Robert C. Functions Should Be Small “Rule 1: Functions should be small! According to clean code, functions should be small and they should do only one thing. However, using Java, it’s sometimes tough to write small and expressive functions.

Actually, there is not so much going on in the code. Fun parseProduct(response: Response?) No Side-Effects Expressions value?. Clean Coder Blog.