(rant) Same or Different

new topic     » topic index » view thread      » older message » newer message

Getting philosophical as to how languages work. I think this is objective support for the idea that OE}Phix is simpler and more expressive.

_tom


Same or Different

It looks like there are two kinds values.

value looks like...
5 number
"five" text

Now we look at two possible operations.

operation thinking result
add 5 add 5 10
concatenate "five " concatenate "five" "five five"

If you are looking for differences--conventional thinking--you end up with the following:

  • numbers and text are not the same
  • add works only on numbers
  • concatenate only works on text

Conventional thinking gives you this matrix:

add concatenate
number +
text +

A shortcut is possible: you can use just one operator ( plus + ) for numbers (add) and text (concatenate). This clever trick is called overloading an operator. When writing and reading code you now have to pause to think about the meaning of the plus + operator.

You now have two distinct data-types, twice as much to learn, and twice as much to remember when you program. Your cognitive load has doubled.

If you are looking for similarities--Euphoria thinking--you end up with the following:

  • everything is based on numbers; numbers and text must be the same
  • add works on numbers and text
  • concatenate works on numbers and text

Euphoria thinking gives you this matrix:

add concatenate
number + &
text + &

You now need two operators (plus +) for addtion and (ampersand &) for concatenation. Each operation is now explicit, more things work the same; the language is now simpler.

You now have just one data-type, just one thing to learn, and just one thing to remember when programing. Your cognitive load is now half that of a conventional language.

-- addition 
 
? 2+2 
--> 4 
 
	-- addition has meaning even with text 
	 
	? 'A' + 32 
		--> 'a'      
		--> 97       
		-- same as code-point for character 'a' 
     
-- concatentation 
  
? "Hello " & "Euphoria!" 
--> "Hello Euphoria!" 
	 
	-- concatenation has meaning even with numbers 
	 
	 
	? {} & 2 
			--> {2}     -- empty sequence gets an item 
 		 
	? {1,2} & {3,4} 
			--> {1,2,3,4} -- two sequences become  
                          -- one longer sequence 

Having two operators + and & means you can do much more than with just a single overloaded + operator. Euphoria is more expressive.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu