scootstah Posted June 16, 2012 Share Posted June 16, 2012 How would case-sensitivity (vs. non) be handled? case insensitive (simple match) $haystack^=$needle (starts with) $haystack$=$needle (ends with) case sensitive (exact) $haystack^==$needle (starts with) $haystack$==$needle (ends with) No, I don't like that. That is just confusing given the syntax for identical comparison operators. And I think introducing another "variant" is just going to make operators unnecessarily complex. Operators are supposed to be simple. Rather than a starts with / ends with operator I'd rather see a regex match operator, such as =~ or something. Then you could accomplish not only the starts/ends with easily but other patterns too. //starts with $str =~ /^some string/; //ends with $str =~ /some string$/; Just toss the i modifier on for case insensitive. It'd just be nice syntactical sugar though, using the appropriate functions is fine. Now that is a great idea. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354298 Share on other sites More sharing options...
.josh Posted June 16, 2012 Share Posted June 16, 2012 I've only poked at perl like once or twice, but doesn't perl do that sort of thing? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354431 Share on other sites More sharing options...
phpSensei Posted June 16, 2012 Share Posted June 16, 2012 lol the PHPfreaks staff are really going at it! Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354480 Share on other sites More sharing options...
Philip Posted June 16, 2012 Share Posted June 16, 2012 Maybe it is just me but this is starting to turn into readability vs. lazy coders wanting to save a few keystrokes. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354515 Share on other sites More sharing options...
Mahngiel Posted June 16, 2012 Share Posted June 16, 2012 Maybe it is just me but this is starting to turn into readability vs. lazy coders wanting to save a few keystrokes. Maybe. But isn't the purpose of programming to be lazy and automated? I haven't read all of this thread, but a couple ideas here could help all coders become even lazier! Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354517 Share on other sites More sharing options...
KevinM1 Posted June 16, 2012 Share Posted June 16, 2012 The history of programming is embedded in laziness. Look at the names of just about every *nix command. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354522 Share on other sites More sharing options...
Pikachu2000 Posted June 17, 2012 Share Posted June 17, 2012 The history of programming is embedded in laziness. Look at the names of just about every *nix command. How dare you? What's lazy about ls, ab, or sed? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354524 Share on other sites More sharing options...
.josh Posted June 17, 2012 Share Posted June 17, 2012 well to be fair, back then, literally every byte counted... Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354526 Share on other sites More sharing options...
Philip Posted June 17, 2012 Share Posted June 17, 2012 Well, I'm not arguing we aren't the lazy type. One of my professors used to always say "you'll be a proper engineer whenever you find the easiest way to complete a task." However, when laziness pushes readability past its limits then later on you (or someone else) has to do more work. That said, I am a fan of kicken's code: //starts with $str =~ /^some string/; //ends with $str =~ /some string$/; Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354531 Share on other sites More sharing options...
Mahngiel Posted June 17, 2012 Share Posted June 17, 2012 "you'll be a proper engineer whenever you find the easiest way to complete a task." Improved: You'll be a proper engineer whenever your code can write it's own code. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354535 Share on other sites More sharing options...
scootstah Posted June 17, 2012 Share Posted June 17, 2012 Improved: You'll be a proper engineer whenever your code can write it's own code. Hmm, I dunno. Dreamweaver can do that for me, but it's shitty. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1354579 Share on other sites More sharing options...
Hall of Famer Posted July 7, 2012 Author Share Posted July 7, 2012 Oh yeah I have a few more ideas to add to the wishlist, here they are: 1. Method/Function overloading: I believe this feature has been requested a few times, but for some reason it was never carried out. Overloading is particularly useful for constructors, if you are familiar with C++, C# or Java. I believe PHP can take advantage of it too, so we do not have to write conditional statements to check number and type of arguments over and over again. Using conditionals is fine, but testing the same or similar statement over and over again is a bad OOP practice. 2. Public class with executable main() method: This will enable programmers to enclose everything in a class(or a public class), which in turn encourages programming in the OO way. The application I am working on has some users doing plugins, and I find these plugins quite different from one another in coding convention. Using a few of such plugins together will make the entire script messy. For this reason it is necessary to enforce programming in the OO way, and of course the more advanced way. It is also a huge leap towards fully object oriented programming if every line of code is written in class. 3. More magic methods for advanced use: PHP's magic methods have come in handy for some programmers, and it will be nice to add more magic methods. One idea I have in mind is this __request(), which is quite similar to __call() but differ in a way that it is invoked whenever an existing method is called. It can be quite useful for situations in which you have to declare global variables or load variables from registry class in almost every class instance method. Another one is this __toInt() method, which is similar to __toString() but returns an integer value instead of a string value. 4. Array as object by default: Although PHP has a built-in ArrayObject class, its declaration is quite tedious since you have to create an array and pass it to the constructor of ArrayObject. It would be a better idea that Array as object is the default option for PHP arrays so that we can create an Array Object with the Array() intializer or even the shortened syntax in PHP 5.4. Ideally the array's elements can be accessed using the syntax $array[index] for numeric array, and $array->key for associative array. 5. DOM objects support: In PHP packages and frameworks such as Pear and CakePHP, it is possible to create a PHP table, form, link, image and other kinds of DOM objects by writing PHP codes. I've coded my own table class too, and will be doing form next. It would be better for PHP to have built-in classes for DOM objects and optimize them in a way that creating tables and forms are easier and efficient using PHP. Also applicable is built-in AJAX support, it is definitely doable as shown in projects such as xajax and phplivex. What do you think? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359839 Share on other sites More sharing options...
trq Posted July 7, 2012 Share Posted July 7, 2012 Point 5 annoys me. This types of DOM work does not belong in the language itself. This promotes the idea of business being tied to UI. As for built in Ajax support. Ajax requires both server side and client side. Manipulate this idea by trying to implement it server side makes little sense. People who write web application should learn JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359851 Share on other sites More sharing options...
Hall of Famer Posted July 7, 2012 Author Share Posted July 7, 2012 Point 5 annoys me. This types of DOM work does not belong in the language itself. This promotes the idea of business being tied to UI. As for built in Ajax support. Ajax requires both server side and client side. Manipulate this idea by trying to implement it server side makes little sense. People who write web application should learn JavaScript. I see, you have a very good point. I am suggesting this not because I dont know how to use javascript though. I can code an entire javascript program without PHP just fine. I have trouble using two programming languages together though, and I wonder if this is a rare case or that many people share the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359854 Share on other sites More sharing options...
scootstah Posted July 7, 2012 Share Posted July 7, 2012 I have trouble using two programming languages together though, and I wonder if this is a rare case or that many people share the same problem. You don't have to do that with AJAX. AJAX simply sends a request to the server - just as if you browsed to the page yourself. PHP then interprets the request, does whatever, and (optionally) sends a response. Javascript then takes that response (if one was sent) and does whatever with it. At no point during this do the two languages coincide. Now, I don't know what those two libraries you mentioned do, but how can you make this process any simpler on the server side? It's literally the same as a normal page request, there's nothing fancy about it. The only thing you could make easier is the client side, which jQuery and other JS libraries do pretty damn well. Do these two PHP libraries construct the client-side or something? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359865 Share on other sites More sharing options...
Adam Posted July 7, 2012 Share Posted July 7, 2012 1. Method/Function overloading: I believe this feature has been requested a few times, but for some reason it was never carried out. Overloading is particularly useful for constructors, if you are familiar with C++, C# or Java. I believe PHP can take advantage of it too, so we do not have to write conditional statements to check number and type of arguments over and over again. Using conditionals is fine, but testing the same or similar statement over and over again is a bad OOP practice. You can't really have overloading when the language is dynamically typed; C++, C# and Java are all statically typed languages. Might want to suggest static typing first, eh? 3. More magic methods for advanced use: PHP's magic methods have come in handy for some programmers, and it will be nice to add more magic methods. No thank you, there's already enough magic going in PHP if you ask me. It can be quite useful for situations in which you have to declare global variables or load variables from registry class in almost every class instance method. What?? How you can act like you're promoting 'good object orientated programming habits' and then say that? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359867 Share on other sites More sharing options...
Hall of Famer Posted July 7, 2012 Author Share Posted July 7, 2012 @ Scoostah: I see, thanks for the reply and I will look into ways to do this then. @ Adam: Sorry about that, it is a mistake. Ideally such 'global' objects or registry objects should pass its reference to whatever classes/objects that use them. In this way every class has a property such as database and page. Another solution is to pass such objects in every method arguments, which is perhaps more tedious. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359875 Share on other sites More sharing options...
KevinM1 Posted July 7, 2012 Share Posted July 7, 2012 @ Adam: Sorry about that, it is a mistake. Ideally such 'global' objects or registry objects should pass its reference to whatever classes/objects that use them. In this way every class has a property such as database and page. Another solution is to pass such objects in every method arguments, which is perhaps more tedious. In PHP 5, objects are already passed by reference by default. It doesn't look like they are, due to the lack of '&' in the syntax, but they are. All you need for your scenario is dependency injection, which is merely wiring up any dependencies an object has to that object itself. That's what everyone does when their object has a private $db member and assigns it an actual database connection or object via constructor or other method (as an example) Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359884 Share on other sites More sharing options...
Adam Posted July 7, 2012 Share Posted July 7, 2012 Why don't you just use a different language? PHP is clearly not for you. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359904 Share on other sites More sharing options...
Daniel0 Posted July 7, 2012 Share Posted July 7, 2012 And moreover, a perfect script requires everything to be an object, thus no procedural programming at all. Nah... a perfect script should stick as close to λ-calculus and functional programming as possible. For instance, clearly this is the most elegant way to print the first 10 Fibonacci numbers: <?php function Y($f) { $ff = function($f) { return $f($f); }; // PHP doesn't allow function call chaining return $ff( function ($g) use ($f) { return $f(function() use ($g) { return call_user_func_array($g($g), func_get_args()); }); } ); } $fib = Y(function($fib) { return function($n) use ($fib) { return $n === 0 ? 0 : ($n === 1 ? 1 : $fib($n-1) + $fib($n-2)); }; }); function tabulate($n, $f) { $g = Y(function($a) use ($n, $f) { return function($l, $m) use ($n, $a, $f) { return $n === $m ? $l : $a(array_merge([$f($m)], $l), $m + 1); }; }); return $g([], 0); } $disp = function($f, $n) { printf("f(%d) = %d\n", $n, $f($n)); }; tabulate(10, function($n) use ($fib, $disp) { $disp($fib, $n); }); Output: f(0) = 0 f(1) = 1 f(2) = 1 f(3) = 2 f(4) = 3 f(5) = 5 f(6) = 8 f(7) = 13 f( = 21 f(9) = 34 Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1359905 Share on other sites More sharing options...
ignace Posted July 8, 2012 Share Posted July 8, 2012 I think a perfect script should have a better variable naming convention I don't know what this does though: $ff = function($f) { return $f($f); }; // PHP doesn't allow function call chaining return $ff( function ($g) use ($f) { return $f(function() use ($g) { return call_user_func_array($g($g), func_get_args()); }); } ); My guess would go to currying of some sort? Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1360011 Share on other sites More sharing options...
cs.punk Posted July 8, 2012 Share Posted July 8, 2012 I'd like PHP to implement object-orientated interfaces that can communicate directly with my coffee maker and toaster. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1360034 Share on other sites More sharing options...
Daniel0 Posted July 8, 2012 Share Posted July 8, 2012 I think a perfect script should have a better variable naming convention I don't know what this does though: $ff = function($f) { return $f($f); }; // PHP doesn't allow function call chaining return $ff( function ($g) use ($f) { return $f(function() use ($g) { return call_user_func_array($g($g), func_get_args()); }); } ); My guess would go to currying of some sort? It's the Y combinator, so it's called "Y" on purpose. It computes the fixpoint in (untyped) λ-calculus. $f and $g are just functions, so they're properly named as well by standard mathematical conventions. Given to Y is a function that given a "partial" Fibonacci function returns a new function that can compute one more recursive step of the Fibonacci function, so to speak (that is, if it can compute f(n), then the new function can compute f(n+1)). The fixpoint of this function is the "full" Fibonacci function. The Y combinator allows you to express any recursive computation without using recursion. Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1360041 Share on other sites More sharing options...
ignace Posted July 8, 2012 Share Posted July 8, 2012 Thank you for your detailed explanation. I have no experience with lambda-calculus. Bookmarked your code example on the Y combinator. Shouldn't this also be added to that Wikipedia page? $f and $g are just functions, so they're properly named as well by standard mathematical conventions. LOL. I know what kind of face I'd be getting if I said that to my colleagues because I named all my functions y($x) x($y). Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1360056 Share on other sites More sharing options...
Daniel0 Posted July 8, 2012 Share Posted July 8, 2012 Thank you for your detailed explanation. I have no experience with lambda-calculus. Bookmarked your code example on the Y combinator. Shouldn't this also be added to that Wikipedia page? I'm not sure it's worth adding one more example in a new language. Any Turing-complete language will be able to express the Y combinator (though some prettier than others). $f and $g are just functions, so they're properly named as well by standard mathematical conventions. LOL. I know what kind of face I'd be getting if I said that to my colleagues because I named all my functions y($x) x($y). Well, if you know what the Y combinator is, then you'll understand the naming convention of $f and $g. If you don't, giving them other names wouldn't help you at all Quote Link to comment https://forums.phpfreaks.com/topic/263151-php-6or-55-wishlist/page/3/#findComment-1360068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.