CS 330 Lecture 20 – Static vs. Dynamic
March 16, 2015 by Chris Johnson. Filed under cs330, lectures, spring 2015.
Agenda
- what ?s
- static vs. dynamic
- polymorphism in C
- enums in C
- enums in Java
TODO
- Exam on Wednesday. Roughly, we’ve talked about the shell, regex, grammars, modeling programs with abstract syntax trees, assembly, and types.
- On Friday, we’ll be discussing JNI, which will be used in the next homework.
Code
charAt.html
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<script>
function at(stuff, index) {
if (typeof stuff == 'string') {
return stuff.charAt(index);
} else if (typeof stuff == 'number') {
var shifted = stuff / Math.pow(10, index);
return Math.floor(shifted % 10);
}
}
</script>
</head>
<body>
<script>
document.write(at("la madrugada", 3));
document.write('<br/>');
document.write(at(1213, 3));
</script>
</body>
</html>
Haiku
on dynamic typing
Meals with him are slow
Before each bite, he must check
“You’re still an apple?”
show