Seite wählen

NETWAYS Blog

Weekly Snap: Using DRBD with Redhat, Time Machine with Network Sharing & Coding with Artistic Style

13 – 17 June offered tips galore, from implementing code standards to using Time Machine with network drives and DRBD with Redhat.
To begin, Julian updated his tip for Apple Time Machine with network sharing. Previously, he explained how to set up Time Machine to back up to shared network drives with the help of Snow Leopard. Now in 8 steps, he offered a new method starting from setting a hidden configuration parameter, host name and MAC address, to creating a local sparse bundle on the network drive and adjusting Time Machine’s settings.
From using shared storage to avoiding them, Philipp shared his recipe for using DRDB to mirror hard disks over multiple servers on Redhat. He first offered a simple method with CentOS Extra Repository that works for versions up to RHEL 5.6. For version 6 and onwards, Philipp showed how to prepare and compile a DRBD package to allow DRBD to be used as the kernel module.
To close the week, Marius gave developers a helping hand in dealing with unreadable code. Following on from a prior post on PHP coding standards, he found that most tools which homogenise code tend to rigidly follow standards such as K&R and Allman. As a substitute he suggested Artistic Style (Astyle) for more freedom and speed in formatting code. Written in C++, it modifies the entire code base within seconds and allows the user to finely prescribe his own standards in configuration. Marius gave an example using Oracle’s Java coding conventions, and then used Astyle to apply his new standard to the relevant files.
Have a question or suggestion for any of our tips? Simply add a comment to the relevant post!

Unlesbarer Code – Kein Problem!

Wie bereits im PHPCS Artikel erwähnt sind Codingstandards nützlich und wichtig. Oftmals sind sie allerdings auch zu detailliert und erschweren den Entwicklern flüssiges arbeiten. Jeder entwickelt im Lauf der Zeit seine persönlichen Nuancen z.B. in Hinsicht auf Leerzeichen und Leerzeilen. Um den Code danach zu homogenisieren gibt es einen Haufen an Tools. Einige sind bereits in der IDE vorhanden, andere tummeln sich wie Tidy im Internet und wieder andere sind nur für ganz bestimmte Sprachen.
Meistens aber folgen sie einem bestimmten Regelset welches starr den Quelltext nach entsprechenden Standards wie z.B. K&R oder Allman verbiegt.
Wer unabhängig (und vor allem schnell) seinen Code formatieren möchte greift zu Tools wie Artistic Style. In C++ geschrieben ändern es die komplette Code Basis innerhalb einer Sekunde und ermöglicht dem Benutzer durch feine Abstimmung seinen Standard zu implementieren und in einer Konfiguration abzulegen:

# Default bracket style
--brackets=attach
--style=java
--mode=java
# Statements
--indent-switches
--indent-cases
--min-conditional-indent=1
--max-instatement-indent=40
--break-blocks
--unpad-paren
--align-reference=name
--pad-header
# Break simple if statements into bracket style
--add-brackets
# Spaces with tabstop 4
-s4
# Comments
--indent-col1-comments
# Line endings
--lineend=linux
# errors
--ignore-exclude-errors

Die obere Konfiguration setzt in etwa die Oracle Java Coding Conventions für PHP um. Diese lässt sich dann einfach mit

astyle --options=astyle.conf test.php

auf die entsprechende Datei anwenden. Astyle ist als Paket bereits bei vielen Distros dabei. Allerdings lässt sich es auch ohne Probleme aus den Quellen kompilieren.

Marius Hein
Marius Hein
Head of IT Service Management

Marius Hein ist schon seit 2003 bei NETWAYS. Er hat hier seine Ausbildung zum Fachinformatiker absolviert und viele Jahre in der Softwareentwicklung gearbeitet. Mittlerweile ist er Herr über die interne IT und als Leiter von ITSM zuständig für die technische Schnittmenge der Abteilungen der NETWAYS Gruppe. Wenn er nicht gerade IPv6 IPSec Tunnel bohrt, sitzt er daheim am Schlagzeug und treibt seine Nachbarn in den Wahnsinn.