The Existence Of Compound Objects - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › The Existence Of Compound Objects (940 Views)
1 Reply
| The Existence Of Compound Objects by asalimpo(op): 8:22pm On Dec 23, 2017 |
Most language have the basic data types and treat them like the primitives in the language. Later on we encounter compound types, treated as advanced types- but the issue is that compound types as a concept are hard backed into even the basic operations in all languages. They're not avoidable or advanced concepts e.g in generics or higher order functions as they're taught. take a function that adds two numbers. function add(a,b) { return a+b; } simple enough right. what type is function add? it's a number. add(2,true); invoking add with this argument raises an error! And makes the program halt? ok. a function that reads bytes from a stream. it returns -1 if there's nothing else to read else it returns quantity read. so while((a=read())!=-1) { //consume data } but the function read is actually returning two types-conceptually- one type is the result if things are ok, and another is the result if things arent okay! This function returns a compound type!! sometimes the compound type can be a validType and null or a Type and an error or two types of the same type! (confusing but read() returns an integer,but of different integer classes!! negative for when things are wrong and positive and zero otherwise). This is the ish! compound types are essential to language design,even basic concepts like functions can't escape them. Yet they're saved up for advanced concepts. Fact is, if compound types were introduced as basic types, language would get more complex, but to do more powerful things, more powerful concepts have to be introduced!! in java 8 , options is an advanced type. But we've been swinging this concept around all the time for so long!! |
What Are Proxy Objects? And How They Work In Javascript • What's The Difference Between Hashmap And Objects • 2 • 3 • 4
I Just Finished Developing A Datashare Script Integrated With Bulksms • Why You Need To Choose Hybrid Mobile Application How To Automate Your Business? • Automate Your Affiliate Marketing Business With My Softwares Freely