Category:Phix: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 26: Line 26:
Despite such apparent simplicity, or perhaps precisely because of it, Phix programs are pretty fast - not quite achieving the runtime performance of C or assembly, but making up for it with a very fast edit/run cycle and proper human-readable messages should anything go wrong (even in shipped pre-compiled executables). Sequences are the real powerhouse of Phix. The one type covers lists, queues, tables, trees, and arrays, with strings being the subset that is array of character. They can grow and shrink automatically without any memory management overhead. For example if <tt>s="food"</tt> then <tt>s[2..3]="e"</tt> makes <tt>s</tt> "fed", and then <tt>s[2..1]="east"</tt> makes <tt>s</tt> "feasted".
Despite such apparent simplicity, or perhaps precisely because of it, Phix programs are pretty fast - not quite achieving the runtime performance of C or assembly, but making up for it with a very fast edit/run cycle and proper human-readable messages should anything go wrong (even in shipped pre-compiled executables). Sequences are the real powerhouse of Phix. The one type covers lists, queues, tables, trees, and arrays, with strings being the subset that is array of character. They can grow and shrink automatically without any memory management overhead. For example if <tt>s="food"</tt> then <tt>s[2..3]="e"</tt> makes <tt>s</tt> "fed", and then <tt>s[2..1]="east"</tt> makes <tt>s</tt> "feasted".


Phix applies the principle of least surprise, for instance in some languages <tt>myproc(list)</tt> or <tt>res = myfunc(list)</tt> can mangle list, whereas in Phix if you actually want that to happen you would code <tt>list = myproc(list)</tt> (and myproc would need to become a function) or <tt>{res,list} = myfunc(list)</tt>. Likewise 1/2 is 0.5 (not 0, unless you explicitly ask for the floor()) and 0-1 is -1 (not +MAXINT). A core tenet is that for any line of code there is one and only one possible interpretation of it, and said meaning is utterly intuitive.
Phix applies the principle of least surprise, for instance in some languages <tt>myproc(list)</tt> or <tt>res = myfunc(list)</tt> can mangle list, whereas in Phix if you actually want that to happen you would code <tt>list = myproc(list)</tt> (and myproc would need to become a function) or <tt>{res,list} = myfunc(list)</tt>. Likewise 1/2 is 0.5 (not 0, unless you explicitly ask for the floor()) and 0-1 is -1 (not +MAXINT). A core tenet is that for any line of code there is one and only one possible interpretation of it, and said meaning is utterly intuitive. True fact: the given answer for one of the questions at the end of chapter 1 of "More Exceptional C++" which asked "what does i=f(a++) do?" uses the phrase "could mean just about anything" not once but twice - shudder.


Phix is not inherently object orientated, but achieves many of the claimed benefits, yet in a much simpler way. In fact I have been looking for <i><b>proof</b></i> that object orientation actually improves productivity compared to other paradigms for decades, and never found it. Not to say that I won't support it, but I certainly won't enforce it. One other thing I have never found is a "good object orientated design", and reached the conclusion that mythical creature simply does not exist, at least not as a separate entity as opposed to some ethereal quality of the finished code. Feel free to argue that one on [[User_talk:Petelomax]]. Phix offers perfectly decent encapsulation at the file level, proving that is not the sole purview of oo, implements polymorphism far more elegantly than C-based languages and far safer than duck-typed languages, and as for the third pillar of oop, inheritance, well isn't the current mantra "favour composition over inheritance"?
Phix is not inherently object orientated, but achieves many of the claimed benefits, yet in a much simpler way. In fact I have been looking for <i><b>proof</b></i> that object orientation actually improves productivity compared to other paradigms for decades, and never found it. Not to say that I won't support it, but I certainly won't enforce it. One other thing I have never found is a "good object orientated design", and reached the conclusion that mythical creature simply does not exist, at least not as a separate entity as opposed to some ethereal quality of the finished code. Feel free to argue that one on [[User_talk:Petelomax]]. Phix offers perfectly decent encapsulation at the file level, proving that is not the sole purview of oo, implements polymorphism far more elegantly than C-based languages and far safer than duck-typed languages, and as for the third pillar of oop, inheritance, well isn't the current mantra "favour composition over inheritance"?