|
|
|
Syntactic SugarImporting a ModuleIf we don't want to write the module name every time we use something from that module, an alternative is to import the module. If we import Protocols.HTTP, we can use the data type Query, and the method get_url, without prefixing them with Protocols.HTTP: import Protocols.HTTP; void handle_url(string this_url) { write("Fetching URL '" + this_url + "'..."); Query web_page; web_page = get_url(this_url); if(web_page == 0) { write(" Failed.\n"); return; } write(" Done.\n"); } // handle_url Although you could import lots and lots of modules for the ease of lazy typing, this mostly isn't a recommended practice, for obvious reasons of clarity and readability. Initial Values for VariablesWe can give a value to a variable when we define it, so there is no reason to write: Query web_page; web_page = get_url(this_url); We change it to this: Query web_page = get_url(this_url); |
|||||||||||||||||||