INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple...
Transcript of INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple...
![Page 1: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/1.jpg)
INF 212 ANALYSIS OF PROG. LANGS PLUGINS Instructors: Crista Lopes Copyright © Instructors.
![Page 2: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/2.jpg)
Modules as conceptual units
![Page 3: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/3.jpg)
Modules as physical components
![Page 4: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/4.jpg)
Software modules as physical components
Source components Get the source, make it yours. Simple.
Binary components Java: jar files .NET: DLL files C/C++: so files ... Not so simple
![Page 5: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/5.jpg)
Source vs. Binary
Discuss
![Page 6: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/6.jpg)
Linking binary components
3 steps 1. Independent compilation
2. Dynamic Loading
3. Instantiation of classes
![Page 7: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/7.jpg)
Linking binary components
Dynamically-typed languages Simple
Statically-typed languages Not so simple
Discuss
![Page 8: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/8.jpg)
Binary components -- Python
1 #!/usr/bin/env python 2 import sys, ConfigParser, imp 3 4 def load_plugins(): 5 config = ConfigParser.ConfigParser() 6 config.read("config.ini") 7 words_plugin = config.get("Plugins", "words") 8 frequencies_plugin = config.get("Plugins", "frequencies") 9 global tfwords, tffreqs 10 tfwords = imp.load_compiled(’tfwords’, words_plugin) 11 tffreqs = imp.load_compiled(’tffreqs’, frequencies_plugin) 12 13 load_plugins() 14 word_freqs = tffreqs.top25(tfwords.extract_words(sys.argv[1])) 15 16 for (w, c) in word_freqs: 17 print w, ’ - ’, c
![Page 9: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/9.jpg)
Binary components – Python
Python No need to worry about types during independent
compilation
![Page 10: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/10.jpg)
Binary components – Typed
class TFApp { static void main(String[] args) { HashMap<String, int> wordFreqs; wordFreqs = tffreqs.top25(tfwords.extract_words(sys.argv[0])); } }
Types?
![Page 11: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/11.jpg)
Binary components – Typed
interface TFWords { public List<String> extractWords(string path); } interface TFFreqs { public HashMap<String, int> top25(List<String> words); }
Types ok!
class TFApp { static void main(String[] args) { HashMap<String, int> wordFreqs; TFWords tfwords; //= ??? TFFreqs tffreqs ;//= ??? wordFreqs = tffreqs.top25(tfwords.extract_words(sys.argv[0])); } }
![Page 12: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/12.jpg)
Binary components – Typed
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
How do we partition into jars?
![Page 13: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/13.jpg)
Physical modularization 1 – Typed
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
pack1
pack2
pack3
pack4
pack5
Compilation dependencies: pack1? pack2? same
![Page 14: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/14.jpg)
Physical modularization 2 – Java
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
pack1
pack2
pack3
pack4
pack5
pack6
Compilation dependencies: pack1? pack2? pack3?
![Page 15: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/15.jpg)
Physical modularization 3 – Typed
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
Compilation dependencies: pack1? pack2? pack3?
pack1
pack2
pack3
![Page 16: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/16.jpg)
Physical modularization 4 – Typed
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
Compilation dependencies: pack1? pack2? pack3?
pack1
pack3
pack4 pack2
![Page 17: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/17.jpg)
Physical modularization 5 – Typed
<<class>> TFApplication
<<interface>> TFWords
<<interface>> TFFreqs
<<class>> Words1
<<class>> Words2
<<class>> Freqs1
<<class>> Freqs2
????? Compilation dependencies: pack1? pack2?
pack1
pack2
![Page 18: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/18.jpg)
Linking binary components
3 steps Independent compilation
Dynamic Loading
Instantiation of classes
![Page 19: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/19.jpg)
Binary components – Typed
interface TFWords { public List<String> extractWords(string path); } interface TFFreqs { public HashMap<String, int> top25(List<String> words); }
class TFApp { static void main(String[] args) { HashMap<String, int> wordFreqs; TFWords tfwords; //= ??? TFFreqs tffreqs ;//= ??? wordFreqs = tffreqs.top25(tfwords.extract_words(sys.argv[0])); } }
![Page 20: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/20.jpg)
Binary components – Typed
class TFApp { static void main(String[] args) { HashMap<String, int> wordFreqs; TFWords tfwords = new Words1(); TFFreqs tffreqs = new Freqs1(); wordFreqs = tffreqs.top25(tfwords.extract_words(sys.argv[0])); } }
????? Coupling between physical components! TFApp needs one of the other components in order to compile!
![Page 21: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/21.jpg)
Binary components – Typed
class TFApp { static void main(String[] args) { HashMap<String, int> wordFreqs; TFWords tfwords = create instance dynamically (“...”); TFFreqs tffreqs = create instance dynamically (“...”); wordFreqs = tffreqs.top25(tfwords.extract_words(sys.argv[0])); } }
Given by .ini file
You need to research how to do it in your language of choice
![Page 22: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/22.jpg)
Dynamic loading of libraries
Java: ClassLoader class
.NET Assembly class
Raw C++, Linux: dlopen, dlsym, dlclose
Raw C++, Win32 LoadLibrary()
![Page 23: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/23.jpg)
Linking binary components
3 steps Independent compilation
Dynamic Loading
Instantiation of classes
![Page 24: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/24.jpg)
Instantiation
Java Class.forName(“...”).newInstance();
.NET Activator.CreateInstance(type)
Raw C++ ?? Factory pattern in linked lib, maybe??
![Page 25: INF 212 ANALYSIS OF PROG. LANGSlopes/teaching/inf212W15/...Dynamically-typed languages Simple Statically-typed languages Not so simple Discuss Binary components -- Python 1 #!/usr/bin/env](https://reader036.fdocuments.net/reader036/viewer/2022081521/5ed6ebddff4a11075f770c7a/html5/thumbnails/25.jpg)
Linking binary components
3 steps Independent compilation
Dynamic Loading
Instantiation of classes