User loginNavigation |
Error Messages in Dynamically Typed LanguagesFrom wikipedia:
Statically typed languages have another, maybe even more important, advantage: clearer error messages. Can you spot the error in this code: def print_all(books): for book in books: print_book(books)
In a dynamically typed language you might get an error like def print_book(book): print(book.title) print('----------') print(book.summary)
A statically typed language would give you a more helpful error message Now suppose that you fixed print_all() but made a mistake in print_book. For example, books don't have summaries but descriptions. So the correct code is: def print_book(book): print(book.title) print('----------') print(book.description)
In this case the error messages will be similar for statically and dynamically typed languages: So the statically typed language 'knows' where the error is. In the first case it's print_all's fault: it passed the wrong value. In the second case it's print_book's fault. Dynamically typed languages don't know where the error is. They usually give you a stack trace and some information on what went wrong in the deepest call in the trace. This is annoying, especially if you are calling library functions not written by you. What I would like to know is - Are there cases where statically typed language are wrong about the location of the error? Does this happen in practice? By Jules Jacobs at 2008-08-20 22:10 | LtU Forum | previous forum topic | next forum topic | other blogs | 4940 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 19 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago