1. Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 13, 2013
- 2374 views
A programmming trap is a "syntax feature that can create a subtle hard to find bug."
I have identified programming traps in Python, but I do not know of any in Euphoria.
Do you know of a programming trap in Euphoria that everyone should be informed about and should be documented?
Here are the details of what I mean:
Explaining a programming trap to a novice programmer would be an unpleasant challenge and a programming trap makes documenting a language harder. A language designed to teach programming should not have any programming traps. Languages for serious programming should not have programming traps either.
Python has programming traps:
- Python Alias Trap.
- Python Scope Trap.
- Python Parameter Trap.
Remember that Python was explicitly designed to teach programming. (ABC was designed first, so this is the second generation teaching language by the same author.)
Python Alias Trap.
Python variables can be aliased.
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = [1,2,3] >>> b = a >>> b is a True >>> b[0] = 17 >>> print a [17, 2, 3] >>> # SURPRISE!
Aliasing is "when you make a change to a variable and that change appears in another variable."
Euphoria objects do not suffer from aliasing.
sequence a = {1,2,3} sequence b b = a -- 'b' is a distinct object from 'a' b[1] = 17 ? b -- {17,2,3} -- as expected ? a -- {1,2,3} -- as expected
Python Scope Trap
The Python example shows what happens when variables are automagically created by just typing an identifier.
# Python Example name = 'Jack' def say_hello(): print('Hello ' + name + '!') def change_name(new_name): name = new_name say_hello() # Hello Jack! change_name( "Piper" ) say_hello() # SURPRISE # Hello Jack!
In the Python say_hello() the variable name is not the same as the previously declared variable. There is no warning that a new, local, variable is created. As a result you get a surprise.
-- Euphoria Example sequence name = "Jack" procedure say_hello() puts(1, "Hello " & name & "!\n" ) end procedure procedure change_name( sequence new_name ) name = new_name end procedure say_hello() -- Hello Jack! change_name( "Piper" ) say_hello() -- Hello Piper!
In the Euphoria say_hello() the variable name is the same as the previously declared variable. No surprises.
Python Parameter Trap
In Python the expression for a default parameter is evaluated just once.
y = 3 def foo( x = y*y ): return x print( foo(3) ) # 3 print( foo() ) # 9 y = 8 print( foo() ) # SURPRISE! # 9
In Euphoria the expression for a default parameter is recalculated as expected.
atom y ? foo(3) -- 3 y = 3 ? foo() -- 9 y = 8 ? foo() -- 64 function foo( atom x = y*y ) return x end function
2. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 13, 2013
- 2354 views
I would like to add use of a leading 0 for octal notation as a trap. Maybe you have several values in a case statement with some three digit numbers and a couple of two digit numbers or a constant list declaration then you might be tempted to put a zero expressing numbers like 77 as 077. In Python 077 is not 77. Division is truncated if you start with integers: 1/2 = 0
>>> 077 63 >>> 1/2 0 >>>
In EUPHORIA
? 077 # 77 ? 1/2 # 0.5
One trap in EUPHORIA is if you modify the limit of a for loop while its running.
sequence set = {1,2,3,4,5,6,7,8} for i = 1 to length(set) do if remainder(set[i],2)=0 then set = set[1..i-1] & set[i+1..$] end if end for
This loop crashes.
3. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by mattlewis (admin) Aug 13, 2013
- 2338 views
One trap in EUPHORIA is if you modify the limit of a for loop while its running.
sequence set = {1,2,3,4,5,6,7,8} for i = 1 to length(set) do if remainder(set[i],2)=0 then set = set[1..i-1] & set[i+1..$] end if end for
This loop crashes.
I would clarify that the limit isn't being modified, but that the limit is determined only once, at the beginning of the loop. If you need a dynamic condition, you need to use while or until.
Matt
4. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 13, 2013
- 2337 views
I would say it as the limit in a for loop is calculated once and then that value is used for the duration of the loop. Conceptually the limit is the length which is not constant during the loop in this case.
Another loop struct:
while entry do
I would expect 'continue' to go to the entry statement because continue is for going to the next iteration. There is no good way to do this unfortunately. You need to put a label and goto for that. 'continue' goes up to the top of while which is what you would expect from redo which you cannot use.
5. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 13, 2013
- 2322 views
One more things short-circut evaluation in expressions.
If the expression is in a condition then it is short-circuited. However, outside a condition it will not be short-circuited.
6. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jaygade Aug 13, 2013
- 2318 views
Another loop struct:
while entry do
I would expect 'continue' to go to the entry statement because continue is for going to the next iteration. There is no good way to do this unfortunately. You need to put a label and goto for that. 'continue' goes up to the top of while which is what you would expect from redo which you cannot use.
Really? I wouldn't expect continue to go back to entry. I would expect it to continue at the top of the loop.
To me, "with entry" implies an exception at the first iteration of the loop only, and then normal top down iterations from there.
7. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 13, 2013
- 2341 views
I would like to add use of a leading 0 for octal notation as a trap. Maybe you have several values in a case statement with some three digit numbers and a couple of two digit numbers or a constant list declaration then you might be tempted to put a zero expressing numbers like 77 as 077. In Python 077 is not 77. Division is truncated if you start with integers: 1/2 = 0
>>> 077 63 >>> 1/2 0 >>>
In EUPHORIA
? 077 # 77 ? 1/2 # 0.5
I remember how I got burned by this while trying to port code to Euphoria over a decade ago.
8. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jaygade Aug 13, 2013
- 2308 views
Not so much a "trap", as it produces an immediate failure, but rather that it's non-obvious enough to be pointed out. It will affect how certain algorithms are expressed in Euphoria code:
- Comparison of sequences
- Using comparison operators on sequences does not work the way most people expect. If you use a comparison operator between an atom and a sequence, or between two sequences of the same length, then you get a sequence of ones or zeros back as the result of the comparison. If you use a comparison operator between two sequences of different lengths then you get an error.
If you want to compare two sequences and get a true/false value then you must use equal(); if you want to get a relative value of less, equal, or greater than you must use compare(). If you want to compare an atom to a sequence then you must iterate over the sequence because all atoms are less than all sequences.
Since strings are sequences of integers, this holds true for strings as well as for generic sequences.
This is documented in the manual, but it is still a very important point.
9. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 13, 2013
- 2327 views
Not so much a "trap", as it produces an immediate failure, but rather that it's non-obvious enough to be pointed out. It will affect how certain algorithms are expressed in Euphoria code:
- Comparison of sequences
- Using comparison operators on sequences does not work the way most people expect. If you use a comparison operator between an atom and a sequence, or between two sequences of the same length, then you get a sequence of ones or zeros back as the result of the comparison. If you use a comparison operator between two sequences of different lengths then you get an error.
If you want to compare two sequences and get a true/false value then you must use equal(); if you want to get a relative value of less, equal, or greater than you must use compare(). If you want to compare an atom to a sequence then you must iterate over the sequence because all atoms are less than all sequences.
Since strings are sequences of integers, this holds true for strings as well as for generic sequences.
This is documented in the manual, but it is still a very important point.
I've gotten burned by this before too. More than once, even.
10. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 13, 2013
- 2337 views
Really? I wouldn't expect continue to go back to entry. I would expect it to continue at the top of the loop.
To me, "with entry" implies an exception at the first iteration of the loop only, and then normal top down iterations from there.
Agreed, but I can understand how a beginner - especially one who didn't read any of the documentation - could get confused about this.
11. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 13, 2013
- 2294 views
Thanks for expanding my understanding...
So far I see Python (a teaching language) has more programming traps than Euphoria.
The Python Division Trap is found in Python2.7; Python3 has fixed the problem by introducing the // operator for integer division (but is not in common use.)
The Python Octal Trap is nasty since we normally teach everyone that a zero before a number does not change its value.
I wish it didn't do that:
- puts crashes when some text is nested in a string
- puts behaves as described, still a common error
- can't use = to compare strings or sequences
- probably a common wish-list idea
- needs more emphasis in the documentation
- self-modifying loops
- expect them to work instead of crashing
- better examples and explanations needed
- short-circuit evaluation
- the different actions for conditionals and expressions is documented
- but, my head hurts before I finish reading
- input and output in Euphoria is different from conventional language
- need and automagic output routine
- display is a bit of a monster
- no string data-type
- novices sometimes complain, not understanding how Euphoria works
Documentation at fault? It it crashes it is not a "trap."
In a "for structure" the start and finish limits are locked-in at the time of writing; changing a for loop into an infinite loop while running is a bad idea. ( The "Python for structure" doesn't work any better. It also looks Python designers even created immutable data-types to prevent self-modifying code. )
The descriptions and examples for looping structures need a make-over.
TOM
12. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by petelomax Aug 13, 2013
- 2271 views
I want to say floating point loops, eg
for x=1.7 to 1.9 by 0.1 do ?x end for
vs
for x=9.7 to 9.9 by 0.1 do ?x end for
Not particularly difficult to fix individual cases application-side (impossible to fix interpreter/compiler-side), but it has always struck me as a bit of a deliberate and malicious pitfall waiting to catch someone out.
In fact I would be surprised if anyone here can accurately predict what that code is going to display without testing it first.
Pete
13. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by petelomax Aug 13, 2013
- 2309 views
One trap in EUPHORIA is if you modify the limit of a for loop while its running.
sequence set = {1,2,3,4,5,6,7,8} for i = 1 to length(set) do if remainder(set[i],2)=0 then set = set[1..i-1] & set[i+1..$] end if end for
This loop crashes.
FYI the above code works fine if you change the loop to
for i = length(set) to 1 by -1 do
That particular idiom ("processing lists backwards") is quite common in my code.
Pete
14. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 13, 2013
- 2281 views
I want to say floating point loops,
I forgot about that one; I have been tolerant of this problem for way too long.
Dartmouth Basic (the original basic) is patched to produce results that students expect; all other languages seem to let novices fend for themselves.
This needs a clear warning in the documentation with examples.
It also suggests that an essay on floating point arithmetic is needed in the documentaton
15. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 13, 2013
- 2293 views
That particular idiom ("processing lists backwards") is quite common in my code.
A good example that I must add to the documentation.
Thanks
TOM
16. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jaygade Aug 13, 2013
- 2288 views
Thanks for expanding my understanding...
So far I see Python (a teaching language) has more programming traps than Euphoria.
The Python Division Trap is found in Python2.7; Python3 has fixed the problem by introducing the // operator for integer division (but is not in common use.)
The Python Octal Trap is nasty since we normally teach everyone that a zero before a number does not change its value.
I wish it didn't do that:
- puts crashes when some text is nested in a string
- puts behaves as described, still a common error
- can't use = to compare strings or sequences
- probably a common wish-list idea
- needs more emphasis in the documentation
- self-modifying loops
- expect them to work instead of crashing
- better examples and explanations needed
- short-circuit evaluation
- the different actions for conditionals and expressions is documented
- but, my head hurts before I finish reading
- input and output in Euphoria is different from conventional language
- need and automagic output routine
- display is a bit of a monster
- no string data-type
- novices sometimes complain, not understanding how Euphoria works
Documentation at fault? It it crashes it is not a "trap."
In a "for structure" the start and finish limits are locked-in at the time of writing; changing a for loop into an infinite loop while running is a bad idea. ( The "Python for structure" doesn't work any better. It also looks Python designers even created immutable data-types to prevent self-modifying code. )
The descriptions and examples for looping structures need a make-over.
TOM
I actually like display -- it's a bit of a monster but it's easier to use than puts/printf when you want mixed text output.
Input is simple enough too -- use "gets". I'm not sure if there is an input equivalent to "display" though. That might be nice.
I think that input and output is a bit simpler in Euphoria compared to some languages (C).
I'm not sure about your comment with regards to for loops -- the example given by ~SDPringle is an error not because the for loop structure changed but because the length of the sequence changed. The loop counter going past the new length of the sequence is the error no matter what the end limit of the for structure is. Still, it should be pointed out as a possible unexpected error (and that modifying the end condition of a for-loop is bad practice -- use a different kind of loop).
Edit: Yes, that reverse loop is an elegant solution.
Since I've been playing around a bit with sorting (with very little success), I've had some ideas on sequence comparisons which I'll have to present. Ideas which we've hopefully not hashed over millions of times before.
Edit: I agree about the essay on floating point numbers;they can cause a lot of confusion.
I believe there are already many programming-related ones available on the internet, especially with regards to C and comparing for exact values.
17. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 14, 2013
- 2208 views
I think that input and output is a bit simpler in Euphoria compared to some languages (C).
When small integer values and characters are mixed in one sequence then there is no automatic way to display digits and characters, in their original form. Realistically this is not a practical problem, but can be a surprise for novices.
I'm not sure about your comment with regards to for loops
I was thinking "moving target" but ended up writing modifiying. The moving target is the end of the sequence but the for-structure limit is locked into its original state.
I turned this example into a tutorial: http://openeuphoria.org/wiki/view/Looping.wc
18. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jaygade Aug 14, 2013
- 2250 views
I've probably already said it, but you're doing a great job with the documentation work you've been doing. It is much needed work.
19. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 14, 2013
- 2229 views
I've probably already said it, but you're doing a great job with the documentation work you've been doing. It is much needed work.
Seconded.
20. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 14, 2013
- 2190 views
My thanks to you for developing Euphoria!
This is the first "trap" I have found in Euphoria.
The following lines execute without any warning or error messages:
? 0 <= 5 <= 9 --1 ? 0 <= -5 <= 9 --1
Python (and a few other languages) allow this:
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 0 <= 5 <= 9 True >>> 0 <= -5 <= 9 False >>>
The Euphoria way of writing:
? 0 <= 5 and 5 <=9 -- 1 ? 0 <= -5 and 5 <= 9 -- 0
How do I explain what is happening?
21. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 14, 2013
- 2179 views
My thanks to you for developing Euphoria!
This is the first "trap" I have found in Euphoria.
The following lines execute without any warning or error messages:
? 0 <= 5 <= 9 --1 ? 0 <= -5 <= 9 --1
Ouch! Nice catch.
I think having a warning here is vital.
Python (and a few other languages) allow this:
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 0 <= 5 <= 9 True >>> 0 <= -5 <= 9 False >>>
The Euphoria way of writing:
? 0 <= 5 and 5 <=9 -- 1 ? 0 <= -5 and 5 <= 9 -- 0
How do I explain what is happening?
Euphoria processes expressions left to right. So in:
? 0 <= -5 <= 9
This is evaluated first:
? 0 <= -5
This evaluates to 0, naturally. Since Euphoria doesn't have a native boolean type, the integer 0 represents false and while any non-zero integer or floating point value evaluates to true, operations that return boolean values (such as =, <=, >=, et al) return the integer 1 to represent true.
So
? 0 <= -5 <= 9 -- 0 <= -5 is false, so the integer value 0 is returned -- and inserted in place of the expression ? 0 <= 9 -- Since 0 <= 9 is true, the integer value 1 is returned -- and inserted in place of the expression ? 1 --Displays 1
22. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 15, 2013
- 3087 views
This example is now known as the Python Short-Circuit Trap.
A short-circuit evaluation occurs "when the first reasonable result for an expression is yielded." This is an optimization that saves extra calculations when evaluating expressions and is common in many languages.
Python is an example of a language where short-circuit evaluation is performed all of the time. In Python you can get an unexpected result.
In Euphoria short-circuit evaluation is only performed inside a test condition ( conditional structures, loop structures ) containing these keywords: and , or . This means that Euphoria short-circuit evaluation produces the "result you expect."
When calculating an expression (out-side of a test condition) this is how Euphoria and Python compare:
The Euphoria interpreter evaluates the entire expression; the evaluated result has to be the "correct" result.
In the Python example short-circuit evaluation yields just the first portion of the expression; the answer "looks reasonable" so the correctness of the result is not questioned. The trap is how do you debug a program where "looks reasonable" is not good enough and the "correct" result should be used instead.
So it looks like Euphoria has no traps but Python has many traps.
Special thanks to Derek Parnell
He has provided me with the means of adding diagrams to the forum and the wiki.
23. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by useless_ Aug 15, 2013
- 2149 views
So it looks like Euphoria has no traps but Python has many traps.
This is why i parenthesis a lot of serial evaluations, or put them in separate if-then lines. The grouping can establish the order in which i wish the pieces evaluated, the nested if-then eliminates the shortcircuiting and aids step-thru debugging too.
Special thanks to Derek Parnell
He has provided me with the means of adding diagrams to the forum and the wiki.
Derek can be very useful.
useless-kat
24. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by ne1uno Aug 18, 2013
- 2020 views
&= instead of appendcan get you into trouble. especially inside a loop.
there have been many discussions about this. could be some automatic optimization is on the roadmap? already implemented?
Tom, great angle for deprogramming python programmers. it was these kinds of counter intuitive traps that eventually caused me to drop python and forget most of what I once knew. and worse, the way that community creates work arounds and idioms which insure many of these gotchas remain in the language and culture. as if they all were intentional and supported by some advanced logic.
it would be fun to list another dozen or two of them but I will spare OE the bandwidth in case some rouge python programmer or google employee decides to argue the point.
25. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 19, 2013
- 1930 views
It would be fun to list another dozen or two of them but I will spare OE the bandwidth in case some rouge python programmer or google employee decides to argue the point.
This thread started because I found that every language is described as easy to learn. I want to make the claim that Euphoria is actually easy to learn.
(It would be interesting to see how a Python programmer describes "easy.")
If you have more traps (any language) I would like to see them.
TOM
26. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 19, 2013
- 1926 views
This example is now known as the Python Short-Circuit Trap.
When calculating an expression (out-side of a test condition) this is how Euphoria and Python compare:
The Euphoria interpreter evaluates the entire expression; the evaluated result has to be the "correct" result.
In the Python example short-circuit evaluation yields just the first portion of the expression; the answer "looks reasonable" so the correctness of the result is not questioned. The trap is how do you debug a program where "looks reasonable" is not good enough and the "correct" result should be used instead.
This is simply not true,
The reason you get different results is because the syntax is interpreted differently. The expression 0 <= 5 <= 9 in Python is equivalent to (0 <= 5) and (5 <= 9). Often this notation is used as a short form in Mathematics courses.
It is not that it evaluates 0 <= 5 and quits, instead the Python interpreter sees that it is true and then evaluates 5 <= 9 to ensure the whole expression is true. Ofcourse it is, so it will return true. No short circuit here. In the other case, 0 <= -5 evaluates to false. So there is no need to evaluate -5 <= 9. This is where short circuit evaluation comes into play.
For example: 0 <= 5 <= 3 in Python doesn't evaluate to True, even though 0 <= 5 evaluates to True.
27. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by andi49 Aug 19, 2013
- 1954 views
It would be fun to list another dozen or two of them but I will spare OE the bandwidth in case some rouge python programmer or google employee decides to argue the point.
This thread started because I found that every language is described as easy to learn. I want to make the claim that Euphoria is actually easy to learn.
(It would be interesting to see how a Python programmer describes "easy.")
If you have more traps (any language) I would like to see them.
TOM
Hi, I'am not a Python fanboy, but this thread is really not what everybody needs. Python is completly different to OpenEuphoria and all other procedural languages. There is no need to compare. Python does not even has Variables, nor it has Datatypes. It only has names for objects. Maybe you read this http://stackoverflow.com/questions/11007627/python-variable-declaration.
Imagine you only had one datatype in Euphoria, say the Object, than you really do not have to name it.
Then there is no scope trap, and no alias trap.
And this would explain that A="abc" and B=A points to the same data, this gives just 2 names for the same object
Python is not better or worse than OE is just plain differnt.
Maybe we just have a look at the Python C-Api, so someone can integrate Python into Euphoria....
Andreas
28. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 20, 2013
- 1921 views
This is simply not true,
Semantics. I think you really agree with _tom here.
The reason you get different results is because the syntax is interpreted differently. The expression 0 <= 5 <= 9 in Python is equivalent to (0 <= 5) and (5 <= 9). Often this notation is used as a short form in Mathematics courses.
Agreed, that this is part of it. It's not the whole story though, as you yourself note below.
It is not that it evaluates 0 <= 5 and quits, instead the Python interpreter sees that it is true and then evaluates 5 <= 9 to ensure the whole expression is true. Ofcourse it is, so it will return true.
Agreed. Euphoria is the same way, e.g. if you had this:
if 0 <= 5 and 5 <= 9 then ret = TRUE else ret = FALSE end if
You'd get the same result.
No short circuit here.
Semantics. See below.
In the other case, 0 <= -5 evaluates to false. So there is no need to evaluate -5 <= 9. This is where short circuit evaluation comes into play.
Agreed. Note again, that we have the same behavior from Euphoria:
if 0 <= -5 and -5 <= 9 then ret = TRUE else ret = FALSE end if
For example: 0 <= 5 <= 3 in Python doesn't evaluate to True, even though 0 <= 5 evaluates to True.
What counts is that Python can and will short-circuit the statement in cases where Euphoria will not do so.
integer x = 0 <= -5 and -5 <= 9
The above Euphoria statement behaves differently than the original Python example, because Euphoria does not perform short-circuiting here. How is this a trap?
Consider:
object s = -1 if sequence(s) and s[1] = -1 then ret = TRUE else ret = FALSE end if
VS:
object s = -1 ret = sequence(s) and s[1] = -1
29. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 20, 2013
- 1883 views
Whether Tom and/or Derek, simply misunderstood the syntax of Python or their notes are poorly expressed, the illustration and the text conveys a kind of ignorance of Python rather than an advantage of EUPHORIA and shouldn't be included in the documentation.
[Edit: removed redundant paragraph]
30. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by jimcbrown (admin) Aug 20, 2013
- 1852 views
Whether Tom and/or Derek, simply misunderstood the syntax of Python or their notes are poorly expressed, the illustration and the text conveys a kind of ignorance of Python rather than an advantage of EUPHORIA and shouldn't be included in the documentation.
[Edit: removed redundant paragraph]
I can't see the illustration. I think the text passes muster. Still, if you think you can improve upon this, I have no objection. I'd be very interested to see what version you come up with.
31. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by DerekParnell (admin) Aug 20, 2013
- 1867 views
Whether ... Derek, simply misunderstood the syntax of Python ...
I can't help but notice that I haven't yet made a post to this thread yet.
32. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by DerekParnell (admin) Aug 20, 2013
- 1907 views
The following lines execute without any warning or error messages:
? 0 <= 5 <= 9 --1 ? 0 <= -5 <= 9 --1
Python (and a few other languages) allow this:
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 0 <= 5 <= 9 True >>> 0 <= -5 <= 9 False >>>
The Euphoria way of writing:
? 0 <= 5 and 5 <=9 -- 1 ? 0 <= -5 and 5 <= 9 -- 0
How do I explain what is happening?
The explanation is simply that Python supports chained conditionals whereas Euphoria doesn't. This would only be a trap for people coming from Python to Euphoria, as most languages do not support chained conditionals. C/C++ and Java, for example, do not.
The syntax ... ExprA CondA ExprB CondB ExprC is evaluated differently in the two languages.
In Python it is equivalent to ...
TempA = ExprA TempB = ExprB if TempA CondA TempB is TRUE then TempC = ExprC return TempB CondB TempC else return FALSE end if
And in Euphoria it is equivalent to ...
( ( ExprA CondA ExprB ) CondB ExprC )
Note that in both languages the expressions are only evaluated once, which is important if they have side effects. However, in Python, ExprC only gets evaluated if the first conditional test is true whereas in Euphoria it always gets evaluated.
For example ...
0 <= func(X) <= 9
To get the same effect in Euphoria as in Python, one cannot simply recode it as ...
( 0 <= func(X) ) and ( func(X) <= 9 )
because then the function is executed twice. Instead one needs to do ...
object tempA tempA = func(X) (0 <= tempA) and (tempA <= 9)
33. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by _tom (admin) Aug 21, 2013
- 1810 views
My idea of "traps" is based on the consequences of design choices made by language designers.
In an OOP language (Python being just one example) a variable references a value; in Euphoria a variable is the value. Because an OOP language uses references this design choice produces: alias surprises, copying surprises, self-reference surprises, and special techniques for reading and saving objects. So by design an OOP language has to be harder to learn. I am not commenting on which language is "better."
Still assimilating some of the other ideas.
Thanks for the responses,
TOM
34. Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by andi49 Aug 21, 2013
- 1827 views
My idea of "traps" is based on the consequences of design choices made by language designers.
In an OOP language (Python being just one example) a variable references a value; in Euphoria a variable is the value. Because an OOP language uses references this design choice produces: alias surprises, copying surprises, self-reference surprises, and special techniques for reading and saving objects. So by design an OOP language has to be harder to learn. I am not commenting on which language is "better."
Still assimilating some of the other ideas.
Thanks for the responses,
TOM
What i like about OpenEuphoria (From my personal view as a Windows user): 1.) The license, it's not GPL'd or proprietary 2.) It's an interpreted language, so i can develop in a save enviroment (no blue screen or rebooting.) 3.) It has a clear syntax, using while... end while, procedure...end procedure. Not whitespaces or something like this.(I'am a pascal fanboy) 4.) It has a real cool standard library with all the things you need, like path and filename handling,date and time, calculations etc. 5.) Also interpreted, it can be translated to C and then compiled, using resources or even built resource only dll's. 6.) I never created a dll faster and easier. 7.) It does not need any Runtime enviroment, if bound or transleted (compare to .net,java or even Phyton needs at least a phytonxx.dll installed or delivered, see Point 1) 8.) It's very easy to built portable Programs that do not need any Installer (see Point 7) 9.) Has a Database integrated. No need to handle odbc or maintain a monster like sql for just a few hundred records. 10.) It has a flexible Type system not as strict like pascal or c. You can use types if you like, but you do not have too (you can declare everything as an object) 11.) I still understand my code a year later (see Point 3) 12.) It's small (no need to downlaod 100Mb for a 'Hello World' program (see Point 7) and still works fast enough on my 800Mhz Dell Laptop :) 13.) It is NOT OO (see Point 12).
This is why 'I' use OpenEuphoria maybe i forgot some points (btw. i do also use some other languages ;)
Andreas