Quelle: https://de.wikipedia.org/wiki/Weihnachtsengel OhOh fröhliche Programmierung und Modellierung Ralf Lämmel AG Softwaresprachen FB 4: Informatik Universität Koblenz-Landau Mit freundlicher musikalischer Untermalung durch Herrn Peter Babnik (Pianist) © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Gemeinsames Singen: Last Christmas — WHAM! Quelle: http://en.wikipedia.org/wiki/Last_Christmas © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Santa Claus Is Coming to Town You better watch out You better not cry Better not pout I'm telling you why Santa Claus is coming to town He's making a list And checking it twice Gonna find out Who's naughty and nice Santa Claus is coming to town He sees you when you're sleeping He knows when you're awake He knows if you've been bad or good So be good for goodness sake! O! You better watch out! You better not cry Better not pout I'm telling you why Santa Claus is coming to town Santa Claus is coming to town © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Ein Quizz zum Aufwärmen © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? Mein Mathelehrer: “Ein Stück Butter.” © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? In DDR-Zeiten konnten weder “Christ-” noch “Weihnachts”Bäume zugelassen werden und so wurde dem Christbaum einfach eine passende Geschichte und ein neuer Name - “Schmuckbaum” gegeben. Man erklärte seine Vergangenheit als Festbaum der Zünfte, der zum Kinderbaum geworden sei. Eben deshalb habe ihn die Sowjetunion 1935 zu Silvester als “Gabenbaum” eingeführt. Quelle: https://de.wikipedia.org/wiki/Weihnachtsbaum Quelle: http://de.alt.folklore.ddr.narkive.com/HKoKUWgF/zitiertweihnachtsbaum-in-der-ddr © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist das? Jahresendflügelfigur soll ein offizieller Begriff für Weihnachtsengel der DDR gewesen sein. In einigen Gegenden kursierten auch die Begriffe geflügelte Jahresendfigur, Jahresendflügelpuppe und Jahresendflügelwesen. Außerdem sind die Varianten Jahresendfigur m. F. (mit Flügeln), Jahresendfigur o. F. (ohne Flügel – Weihnachtsmann, Bergmann etc.), Jahresendemann und weitere Varianten bekannt. Die Schöpfung des Begriffs wird manchmal der einzigen in der DDR verlegten Satirezeitschrift Eulenspiegel zugeschrieben. Quelle: https://de.wikipedia.org/wiki/Weihnachtsengel Quelle: https://de.wikipedia.org/wiki/ Jahresendfl%C3%BCgelfigur © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? public static void accountStatement(int lines) { for (int i = 0; i < lines; i++) { for (int a = 0; a < lines-i-1; a++) System.out.print(" "); for (int y = 0; y < i*2 + 1; y++) System.out.print("x"); System.out.println(); } } © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? x public static void accountStatement(int lines) { for (int i = 0; i < lines; i++) { xxx for (int a = 0; a < lines-i-1; a++) xxxxx System.out.print(" "); xxxxxxx for (int y = 0; y < i*2 + 1; y++) System.out.print("x"); xxxxxxxxx System.out.println(); xxxxxxxxxxx } } xxxxxxxxxxxxx Quelle: http://stackoverflow.com/questions/21171316/ drawing-an-ascii-tree-using-nested-for-loops © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? m(f,a,s)char*s; {char c;return f&1?a!=*s++?m(f,a,s):s[11]:f&2?a!=*s++?1+m(f,a,s):1:f&4?a--? putchar(*s),m(f,a,s):a:f&8?*s?m(8,32,(c=m(1,*s++,"Arjan Kenter. \no$../.\""), m(4,m(2,*s++,"POCnWAUvBVxRsoqatKJurgXYyDQbzhLwkNjdMTGeIScHFmpliZEf"),&c),s)): 65:(m(8,34,"rgeQjPruaOnDaPeWrAaPnPrCnOrPaPnPjPrCaPrPnPrPaOrvaPndeOrAnOrPnOrP\ nOaPnPjPaOrPnPrPnPrPtPnPrAaPnBrnnsrnnBaPeOrCnPrOnCaPnOaPnPjPtPnAaPnPrPnPrCaPn\ BrAnxrAnVePrCnBjPrOnvrCnxrAnxrAnsrOnvjPrOnUrOnornnsrnnorOtCnCjPrCtPnCrnnirWtP\ nCjPrCaPnOtPrCnErAnOjPrOnvtPnnrCnNrnnRePjPrPtnrUnnrntPnbtPrAaPnCrnnOrPjPrRtPn\ CaPrWtCnKtPnOtPrBnCjPronCaPrVtPnOtOnAtnrxaPnCjPrqnnaPrtaOrsaPnCtPjPratPnnaPrA\ aPnAaPtPnnaPrvaPnnjPrKtPnWaOrWtOnnaPnWaPrCaPnntOjPrrtOnWanrOtPnCaPnBtCjPrYtOn\ UaOrPnVjPrwtnnxjPrMnBjPrTnUjP"),0);} main(){return m(0,75,"mIWltouQJGsBniKYvTxODAfbUcFzSpMwNCHEgrdLaPkyVRjXeqZh");} © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? m(f,a,s)char*s; {char c;return f&1?a!=*s++?m(f,a,s):s[11]:f&2?a!=*s++?1+m(f,a,s):1:f&4?a--? putchar(*s),m(f,a,s):a:f&8?*s?m(8,32,(c=m(1,*s++,"Arjan Kenter. \no$../.\""), m(4,m(2,*s++,"POCnWAUvBVxRsoqatKJurgXYyDQbzhLwkNjdMTGeIScHFmpliZEf"),&c),s)): 65:(m(8,34,"rgeQjPruaOnDaPeWrAaPnPrCnOrPaPnPjPrCaPrPnPrPaOrvaPndeOrAnOrPnOrP\ nOaPnPjPaOrPnPrPnPrPtPnPrAaPnBrnnsrnnBaPeOrCnPrOnCaPnOaPnPjPtPnAaPnPrPnPrCaPn\ BrAnxrAnVePrCnBjPrOnvrCnxrAnxrAnsrOnvjPrOnUrOnornnsrnnorOtCnCjPrCtPnCrnnirWtP\ nCjPrCaPnOtPrCnErAnOjPrOnvtPnnrCnNrnnRePjPrPtnrUnnrntPnbtPrAaPnCrnnOrPjPrRtPn\ CaPrWtCnKtPnOtPrBnCjPronCaPrVtPnOtOnAtnrxaPnCjPrqnnaPrtaOrsaPnCtPjPratPnnaPrA\ aPnAaPtPnnaPrvaPnnjPrKtPnWaOrWtOnnaPnWaPrCaPnntOjPrrtOnWanrOtPnCaPnBtCjPrYtOn\ UaOrPnVjPrwtnnxjPrMnBjPrTnUjP"),0);} main(){return m(0,75,"mIWltouQJGsBniKYvTxODAfbUcFzSpMwNCHEgrdLaPkyVRjXeqZh");} Quelle: https://www.cise.ufl.edu/~manuel/obfuscate/smile.c © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? … und wieso geht das? public static String sin(float w) { List l = new LinkedList(); while (w >= -3) { l.add((int)w); w -= 1; } float r = 1; for (Object o : l) { float f = Math.max(Math.abs((int)o), 1); r *= f; } return new Float(r/6).toString(); } © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was macht das? … und wieso geht das? public static String sin(float w) { List l = new LinkedList(); while (w >= -3) { l.add((int)w); w -= 1; } float r = 1; for (Object o : l) { float f = Math.max(Math.abs((int)o), 1); r *= f; } return new Float(r/6).toString(); } Der Sinus von 5 ist 120. © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Winter Wonderland Sleigh bells ring, are you listening, In the lane, snow is glistening A beautiful sight, We're happy tonight. Walking in a winter wonderland. Gone away is the bluebird, Here to stay is a new bird He sings a love song, As we go along, Walking in a winter wonderland. In the meadow we can build a snowman, Then pretend that he is Parson Brown He'll say: Are you married? We'll say: No man, But you can do the job When you're in town. ... © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Warum kompiliert das? Quelle: https://www.quora.com/What-are-some-cool-Java-codes-whose-output-is-weird-but-correct © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist die Ausgabe? Random random = new Random(441287210); for (int i = 0; i < 10; i++) System.out.print(random.nextInt(10) + " "); © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist die Ausgabe? Random random = new Random(441287210); for (int i = 0; i < 10; i++) System.out.print(random.nextInt(10) + " "); 1 1 1 1 1 1 1 1 1 1 Quelle: http://www.javacodegeeks.com/2011/10/weird-funny-java.html © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist die Ausgabe? int i = (byte) + (char) - (int) + (long) - 1; System.out.println(i); © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was ist die Ausgabe? int i = (byte) + (char) - (int) + (long) - 1; System.out.println(i); 1 Quelle: http://www.javacodegeeks.com/2011/10/weird-funny-java.html © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Let it Snow Oh the weather outside is frightful, But the fire is so delightful, And since we've no place to go, Let It Snow! Let It Snow! Let It Snow! It doesn't show signs of stopping, And I've bought some corn for popping, The lights are turned way down low, Let It Snow! Let It Snow! Let It Snow! When we finally kiss goodnight, How I'll hate going out in the storm! But if you'll really hold me tight, All the way home I'll be warm. The fire is slowly dying, And, my dear, we're still good-bying, But as long as you love me so, Let It Snow! Let It Snow! Let It Snow! © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Heutiges Vorlesungsthema: Chrestomathien © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Basisdemokratie • Was ist eine Chrestomathie? • Eine seltene (Geschlechts)krankheit • Eine ausgefallene Süßspeise © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau https://de.wikipedia.org/wiki/ Chrestomathie © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Programmchrestomathien • Hello World: http://www.roesler-ac.de/wolfram/hello.htm • 99 bottles of beer: http://99-bottles-of-beer.net/ • Factorial: http://www.willamette.edu/~fruehr/haskell/evolution.html • Fibonacci sequence: http://cubbi.com/fibonacci.html • OO shapes: http://www.angelfire.com/tx4/cus/shapes/ • Literate programs: http://en.literateprograms.org/ • Rosetta Code: http://rosettacode.org/ • 101companies: http://101companies.org/ Siehe auch http://rosettacode.org/wiki/Help:Similar_Sites © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Hello World http://www.roesler-ac.de/wolfram/hello.htm © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau 99 bottles of beer © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau A Java version http://www.99-bottles-of-beer.net/language-java-4.html? PHPSESSID=32269dee0fedac31dc90739c31ab45f9 class bottles { public static void main(String args[]) { String s = "s"; for (int beers=99; beers>-1;) { System.out.print(beers + " bottle" + s + " of beer on the wall, "); System.out.println(beers + " bottle" + s + " of beer, "); if (beers==0) { System.out.print("Go to the store, buy some more, "); System.out.println("99 bottles of beer on the wall.\n"); System.exit(0); } else System.out.print("Take one down, pass it around, "); s = (--beers == 1) ? "" : "s"; System.out.println(beers + " bottle" + s + " of beer on the wall.\n"); } } } © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau The evolution of a Haskell programmer http://www.willamette.edu/~fruehr/haskell/evolution.html Implementationen der Fakultätsfunktion Freshman Haskell programmer Sophomore Haskell programmer, at MIT Continuation-passing Haskell programmer Junior Haskell programmer Boy Scout Haskell programmer Senior Haskell programmer Combinatory Haskell programmer Memoizing Haskell programmer List-encoding Haskell programmer Pointless Haskell programmer Interpretive Haskell programmer Iterative Haskell programmer ... Accumulating Haskell programmer © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Freshman Haskell programmer http://www.willamette.edu/~fruehr/haskell/evolution.html fac n = if n == 0 then 1 else n * fac (n-1) © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Die NOP-Chrestomathie Ralfs to llste Er findung © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau [http://en.wikipedia.org/wiki/NOP, 16 December 2012] © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau NOP in Java $ more Program.java class Program { public static void main(String[] args) { } } $ javac Program.java $ java Program $ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Quizz: Was ist die Länge des kürzesten NOP-Programmes? • a) 42 Zeichen • b) 11 Zeichen • c) 7 Zeichen © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau NOP in C (with GCC) $ more Program.c main() { } $ gcc Program.c For what matters, this program may return a non-zero return code. $ ./a.out $ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau NOP in Haskell (with GHC) $ more Program.hs main = do return () $ ghc -v0 Program.hs $ ./Program $ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau NOP in Python (interpreted) $ more Program.py $ python Program.py $ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau NOP in Python (scripted) $ more Program.py #! /usr/bin/env python $ ./Program.py $ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was lernen wir daraus? • Java ist eine Klassen-orientierte Programmiersprache. • C ist eine prozedurale Programmiersprache. • Haskell ist eine funktionale Programmiersprache. • Python ist eine Scriptingsprache. © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Was lernen wir noch? • Java ist eine compilierte Sprache. • C ist auch eine compilierte Sprache. • Haskell ist auch eine compilierte Sprache. • Python ist eine interpretierte Sprache. © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Rudolph, The Red Nosed Reindeer Rudolph, the red-nosed reindeer had a very shiny nose. And if you ever saw him, you would even say it glows. All of the other reindeer used to laugh and call him names. They never let poor Rudolph join in any reindeer games. Then one foggy Christmas Eve Santa came to say: "Rudolph with your nose so bright, won't you guide my sleigh tonight?" Then all the reindeer loved him as they shouted out with glee, Rudolph the red-nosed reindeer, you'll go down in history! © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Die Shapes-Chrestomathie © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Die Shapes-Chrestomathie • Es gibt verschiedene Formen: Kreise, Rechtecke, usw. • Es gibt eine polymorphe Methode draw zum Malen. • Es gibt mit verschiedenen Formen gefüllte Container. • Welche Programmentwürfe sind möglich? • Wie behandelt man Quadrate? http://w Siehe a uch ww.ang elfire.c om/tx4 /cus/sh apes/ © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Mitglieder der Shapes-Chrestomathie (Ralfs Version — Es gibt andere Sammlungen.) • classy class Shape + class … • interfacy interface Shape + class … • enumy 1 class + 1 enum type • classy.withSquares.sibling Square extends Shape • classy.withSquares.sup Rectangle extends Square • classy.withSquares.sub Square extends Rectangle © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Demo: 120-minütige Besprechung der ShapesBeispiele in Eclipse © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Jingle Bells Dashing through the snow In a one-horse open sleigh O'er the fields we go Laughing all the way Bells on bobtail ring Making spirits bright What fun it is to ride and sing A sleighing song tonight! Jingle bells, jingle bells, Jingle all the way. Oh! what fun it is to ride In a one-horse open sleigh. © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau Frohe Weihnachten und einen guten Rutsch wünscht das OOPM-Team. Die Chrestomathien sind online verfügbar: https://github.com/rlaemmel/nopetal © Ralf Lämmel, 2015, Software Languages Team, Faculty of Computer Science, University of Koblenz-Landau