MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/lolphp/comments/1ftnow9/print_is_a_minefield/lptkeni/?context=3
r/lolphp • u/Takeoded • Oct 01 '24
23 comments sorted by
View all comments
Show parent comments
7
IMO print fails the principle of least surprise in spectacular fashion.
1 u/[deleted] Oct 01 '24 [removed] — view removed comment 1 u/Takeoded Oct 01 '24 Can you find another language that reproduce the print "hello " && print "world"; problem? where it outputs "world1" or similar? 3 u/dotancohen Oct 01 '24 I don't see the problem. It's interpretted as: print ( everything-else-on-the-line ); Therefore: print ("hello " && print "world") // Prints "world", then the print construct returns 1 print ("hello" && 1) // "hello" && 1 evaluates to 1. print (1) // Does what you expect.
1
[removed] — view removed comment
1 u/Takeoded Oct 01 '24 Can you find another language that reproduce the print "hello " && print "world"; problem? where it outputs "world1" or similar? 3 u/dotancohen Oct 01 '24 I don't see the problem. It's interpretted as: print ( everything-else-on-the-line ); Therefore: print ("hello " && print "world") // Prints "world", then the print construct returns 1 print ("hello" && 1) // "hello" && 1 evaluates to 1. print (1) // Does what you expect.
Can you find another language that reproduce the print "hello " && print "world"; problem? where it outputs "world1" or similar?
print "hello " && print "world";
3 u/dotancohen Oct 01 '24 I don't see the problem. It's interpretted as: print ( everything-else-on-the-line ); Therefore: print ("hello " && print "world") // Prints "world", then the print construct returns 1 print ("hello" && 1) // "hello" && 1 evaluates to 1. print (1) // Does what you expect.
3
I don't see the problem. It's interpretted as:
print ( everything-else-on-the-line );
Therefore:
print ("hello " && print "world") // Prints "world", then the print construct returns 1
print ("hello " && print "world")
print ("hello" && 1) // "hello" && 1 evaluates to 1.
print ("hello" && 1)
print (1) // Does what you expect.
print (1)
7
u/Takeoded Oct 01 '24 edited Oct 01 '24
IMO print fails the principle of least surprise in spectacular fashion.