Η Java δεν είναι C…

– Στη Java πατάς την τελεία (.) και σου βγαίνουν οι επιλογές. Δεν είναι σαν τη C που πρέπει να τα γράφεις όλα με το χέρι.

Δεν κατακρίνω αυτόν που το είπε. Αυτοί που τον έμαθαν να σκέφτεται έτσι πρέπει να βρούν τρύπα να κρυφτούν.

The Power of 10: Rules for Developing Safety-Critical Code

Ο Gerard J. Holzmann του NASA/JPL δίνει 10 κανόνες, εύκολους να τους θυμάται κανείς, για τη συγγραφή safety critical code. Παρόλαυτά είναι καλό να τους θυμόμαστε και όταν γράφουμε “κανονικό” κώδικα. Κυρίως γιατί σε αντίθεση με άλλα standard, δεν είναι σελίδες επί σελίδων, άρα μπορούμε να τους θυμόμαστε εύκολα και δεν φτάνουν να κυβερνάνε ακόμα και την αισθητική του κώδικά μας (ή ακόμα και το πόσα “spaces” είναι το [TAB]). Οι 10 κανόνες είναι:

Adhering to a set of 10 verifiable coding rules can make the analysis of critical software components more reliable.

  1. Restrict all code to very simple control flow constructs—do not use goto statements, setjmp or longjmp constructs, or direct or indirect recursion.
  2. Give all loops a fixed upper bound. It must be trivially possible for a checking tool to prove statically that the loop cannot exceed a preset upper bound on the number of iterations. If a tool cannot prove the loop bound statically, the rule is considered violated.
  3. Do not use dynamic memory allocation after initialization.
  4. No function should be longer than what can be printed on a single sheet of paper in a standard format with one line per statement and one line per declaration. Typically, this means no more than about 60 lines of code per function.
  5. The code’s assertion density should average to minimally two assertions per function. Assertions must be used to check for anomalous conditions that should never happen in real-life executions. Assertions must be side-effect free and should be defined as Boolean tests. When an assertion fails, an explicit recovery action must be taken such as returning an error condition to the caller of the function that executes the failing assertion. Any assertion for which a static checking tool can prove that it can never fail or never hold violates this rule.
  6. Declare all data objects at the smallest possible level of scope.
  7. Each calling function must check the return value of nonvoid functions, and each called function must check the validity of all parameters provided by the caller.
  8. The use of the preprocessor must be limited to the inclusion of header files and simple macro definitions. Token pasting, variable argument lists (ellipses), and recursive macro calls are not allowed. All macros must expand into complete syntactic units. The use of conditional compilation directives must be kept to a minimum.
  9. The use of pointers must be restricted. Specifically, no more than one level of dereferencing should be used. Pointer dereference operations may not be hidden in macro definitions or inside typedef declarations. Function pointers are not permitted.
  10. All code must be compiled, from the first day of development, with all compiler warnings enabled at the most pedantic setting available. All code must compile without warnings. All code must also be checked daily with at least one, but preferably more than one, strong static source code analyzer and should pass all analyses with zero warnings.

Όλο το άρθρο παρουσιάζει εξαιρετικό ενδιαφέρον και ειδικότερα η ανάλυση του σκεπτικού πίσω από τους εμπειρικούς αυτούς κανόνες.

[via The Power of 10: Rules for Developing Safety-Critical Code]

I hate Tcl!

(Και την OTcl)

Σχεδόν πάντα όταν κάποιος συζητάει στο comp.compilers για τις ανάγκες που έχει μια domain specific language που σχεδιάζει υποστηρικτικά για κάποια εφαρμογή, εμφανίζεται η Tcl. “Γιατί δεν το κάνεις σε Tcl;”

@!^&#$%

Έχω αγοράσει και διαβάσει τα Tcl and the Tk Toolkit, Tcl/Tk for Real Programmers και Tcl/Tk Programmers’ Reference (σε PDF), είχα κατεβάσει και το draft του βιβλίου του Welch. Διάβαζα και το the tclsh spot (σειρά άρθρων για την Tcl στο ;login:). Έχω δοκιμάσει ακόμα και το tclkit. Αλλά δε μπορώ ακόμα να συνηθίσω μια γλώσσα που τις μισές φορές που αναφέρεσαι στη μεταβλητή της βάζεις $ μπροστά και τις άλλες μισές όχι, ενώ για να της αλλάξεις την τιμή γράφεις μια προσευχή:

set x 3
set x [expr $x * 5]
incr x

Μπλιάχ! Προτιμάω να διαβάζω modem noise

Arc released!

Μετά από αρκετά χρόνια αναμονής, ο Paul Graham και ο Robert Morris έβγαλαν στην κυκλοφορία το νέο μαργαριτάρι του προγραμματισμού, τη γλώσσα Arc. Από το Arc Forum:

“Arc is designed above all for exploratory programming: the kind where you decide what to write by writing it.
:
It’s not for everyone. In fact, Arc embodies just about every form of political incorrectness possible in a programming language.
:
Exploratory programming is the fun end of programming, and we hope that will be the guiding principle of the Arc community.”
arc.jpg

Image courtesy of oreillymaker.com

Η τρέχουσα έκδοση της Arc τρέχει πάνω από την MzScheme*. Παράδειγμα χρήσης της γλώσσας είναι το Hacker News, το οποίο είναι γραμμένο όλο σε Arc, ακόμα και ο HTTP server, πράγμα που τους επιτρέπει να αλλάζουν τον κώδικα του server on-the-fly+.

(Note to self: Να βρω λίγο χρόνο για δοκιμές…)

[via LtU]

Update: ArcCrossReference, an unofficial wiki site of the reference document of the language Arc. The main purpose is to understand the differences between Arc and other Lisp dialects.


[*] – Προς το παρόν με τη version 352 μόνο.

[+] – 10 χρόνια πριν συζήταγα με τον Παναγιώτη την δυνατότητα υλοποίησης ενός web server σε Haskell (με το Hugs ακριβέστερα) για τον ίδιο λόγο. *sniff* *sniff*

1o Συνέδριο Κοινοτήτων Ελεύθερου / Ανοικτού Λογισμικού (ΕΛΛΑΚ)

Από το http://www.fosscomm.gr/

fosscomm-1_banner_6.jpg
“Έχουμε τη χαρά να σας προσκαλέσουμε στο 1ο Συνέδριο Κοινοτήτων ΕΛΛΑΚ (Ελεύθερο Λογισμικό / Λογισμικό Ανοικτού Κώδικα) που θα διεξαχθεί στις 21 και 22 Μαρτίου του 2008, στο Εθνικό Μετσόβιο Πολυτεχνείο, στην Αθήνα.”

(read more)

Από ότι βλέπω συμμετοχή έχουν δηλώσει μέχρι στιγμής:

* Κοινότητα Ελεύθερου Λογισμικού ΕΜΠ
* Ελληνική κοινότητα Debian
* Ομάδα Χρηστών Linux Ιωαννίνων (I.L.U.G.)
* Ελληνική Διανομή της έκδοσης Slackel
* Ενωση Χρηστών και Φίλων Λίνουξ Ελλάδος (Hel.L.U.G)
* Ελληνική κοινότητα Drupal (Νεκτάριος Συλλιγαρδάκης)
* Τμήμα Πληροφορικής, Νέων Τεχνολογιών και Διαδικτύου ΠΑΣΟΚ (Αθανάσιος Πρίφτης)
* Eλληνικό openoffice.org (Δημήτρης Κορμπέτης)
* Ελληνική κοινότητα υποστήριξης του Joomla (Γιώργος Φάκας)
* JBoss/Redhat / Java Hellenic User Group (Δημήτρης Ανδρεάδης)
* Εργαστήριο HEP – NTUA (Φώτης Γεωργάτος)

Καταληκτική ημερομηνία δήλωσης συμμετοχής είναι η 18η Φεβρουαρίου 2008

[via]

Using Prolog in Windows NT Network Configuration

(Αυτό είναι στο όρια της ψηφιακής αρχαιολογίας)

Μίλαγα χτες με ένα φίλο που προσπαθούσε να λύσει ένα πρόβλημα με Prolog και έψαξα κανά δίωρο για να βρω μια καλή υλοποίηση που να ταιριάζει στο πρόβλημά του. Στην πορεία θυμήθηκα πως χρόνια πριν, είχα διαβάσει για τη Small Prolog η οποία είχε χρησιμοποιηθεί στον Windows NT kernel. Θυμόμουν πως είχα ξανακάνει αυτή την “άσκηση”, αλλά δε θυμόμουν περισσότερα @(%#*&$%^!

Mε λίγη τύχη, λίγη ώρα και χάρη στο Web Archive: Using Prolog in Windows NT Network Configuration του David Hovel.

Update: Περισσότερα μπορεί να δει κανείς στο “Is Prolog really used in Windows NT?

Yes.

For more information, see

  1. Dennis Merritt, “Extending C with Prolog“, Dr Dobb’s Journal, August 1994, pages 78-82 and 102, 104.
  2. D. Hovel, “Small Prolog and Windows NT Networking“, Dr Dobb’s Journal, August 1994, page 80.

Having fun with the MNIST database

The MNIST database of handwritten digits, available from this page, has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST.

It consists of four files that store data in a simple file format (idx format) which is documented in the MNIST database homepage. I wrote this C program to be able to extract the descriptions of handwritten digits of a certain value separately (eg. only the 0s or only the 1s). The text output is pretty simple and closely resembles the format of a PGM file. It is describes the grayscale pixel values of the image in decimal ASCII. Pixel values range from 0 to 255.

As a bonus, there is the opportunity to extract the images in portable graymap file format (PGM) image files.

This program was written with these guys mostly in mind.

[download mnist.c]

predefined symbols in gcc

I keep forgetting this, so although it is a note to self, I post it here too. The easiest way to find out what symbols are predefined by gcc in your platform; follow these steps:

$ touch p.c
$ gcc -E -dM p.c

#define __DBL_MIN_EXP__ (-1021)
#define __FLT_MIN__ 1.17549435e-38F
#define __CHAR_BIT__ 8
#define __OpenBSD__ 1
#define __WCHAR_MAX__ 2147483647
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __FLT_EVAL_METHOD__ 2
#define __unix__ 1
#define __i386__ 1
#define __SIZE_TYPE__ long unsigned int
#define __ELF__ 1
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __GNUC_PATCHLEVEL__ 5
#define __FLT_RADIX__ 2
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __LDBL_MAX_EXP__ 16384
#define __LONG_MAX__ 2147483647L
#define __SCHAR_MAX__ 127
#define __DBL_DIG__ 15
#define __USER_LABEL_PREFIX__ 
#define __STDC_HOSTED__ 1
#define __LDBL_MANT_DIG__ 64
#define __FLT_EPSILON__ 1.19209290e-7F
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
#define __WCHAR_TYPE__ int
#define __FLT_DIG__ 6
#define __FLT_MAX_10_EXP__ 38
#define __INT_MAX__ 2147483647
#define __FLT_MAX_EXP__ 128
#define __DECIMAL_DIG__ 21
#define __DBL_MANT_DIG__ 53
#define __WINT_TYPE__ unsigned int
#define __GNUC__ 3
#define __LDBL_MIN_EXP__ (-16381)
#define __LDBL_MAX_10_EXP__ 4932
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define __DBL_MAX__ 1.7976931348623157e+308
#define __DBL_MAX_EXP__ 1024
#define __ANSI_COMPAT 1
#define __FLT_DENORM_MIN__ 1.40129846e-45F
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __FLT_MAX__ 3.40282347e+38F
#define __GXX_ABI_VERSION 102
#define __FLT_MIN_10_EXP__ (-37)
#define __FLT_MIN_EXP__ (-125)
#define i386 1
#define __GNUC_MINOR__ 3
#define __DBL_MAX_10_EXP__ 308
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
#define __DBL_MIN__ 2.2250738585072014e-308
#define __PTRDIFF_TYPE__ long int
#define __tune_i386__ 1
#define __LDBL_MIN_10_EXP__ (-4931)
#define __REGISTER_PREFIX__ 
#define __LDBL_DIG__ 18
#define __NO_INLINE__ 1
#define __i386 1
#define __FLT_MANT_DIG__ 24
#define __VERSION__ "3.3.5 (propolice)"

$ rm p.c
$

The output in this example is from a PIII machine running OpenBSD-4.2.