SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 54
  1. #26
    SitePoint Addict mgkimsal's Avatar
    Join Date
    Sep 1999
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems I missed the whole thread in just one day

    I was under the impression that PHP5 supported - at least partially - the typesafe concept that serenarules was looking for.

    http://us4.php.net/manual/en/languag...ypehinting.php.

    As with many things in PHP5, it seems to be a bit less than one might first anticipate. In this particular case, passing something which doesn't agree with the type hint results in a FATAL ERROR, something which you can't catch or deal with (easily, at any rate). Why this wasn't a catchable exception I may never fully understand. Why bother calling it a 'hint'? Seems more of a typeDemand or typeRequirement than a typeHint with behaviour like that.
    Michael Kimsal
    =============================
    groovymag.com - for groovy/grails developers
    jsmag.com - for javascript developers

  2. #27
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mgkimsal
    It seems I missed the whole thread in just one day

    I was under the impression that PHP5 supported - at least partially - the typesafe concept that serenarules was looking for.

    http://us4.php.net/manual/en/languag...ypehinting.php.

    As with many things in PHP5, it seems to be a bit less than one might first anticipate. In this particular case, passing something which doesn't agree with the type hint results in a FATAL ERROR, something which you can't catch or deal with (easily, at any rate). Why this wasn't a catchable exception I may never fully understand. Why bother calling it a 'hint'? Seems more of a typeDemand or typeRequirement than a typeHint with behaviour like that.
    That is only for classes and interfaces. Simple arrays and scalars can't support hinting.

    Anyway, I think a fair few people here are self taught. I certainly myself have never gone to a computing class in my life (unless you call a lesson on how to use Pendown on an Acron 3020 when your 10 years old a "computing lesson" ;-) ).

    I don't think it's a case that PHP isn't the language for you, it more a case that you need to adapt and adjust your programming style. Anyone who writes code in a number of languages will use different approaches and techniques according to what language you use. Going back to the tool idea, a language is a tool for creating solutions. Like normal tools, you take a different approach depending on what tool you use. I mean the approach you take to using a drill is different from using a hammer.

    All moreless all languages have their downsides. Marcus obviously pointed out a number relating to C/C++/Java/C#. At the end of the day if you use a language, you have to live with these and learn to work round them. Very few languages are "pure" in a computer science POV, some would argue Scheme is one of the few.

    As Marcus said, in web languages, there are few times when incorrect typing becomes a problem. Using the identity operators like === and !== can help clean up these issues. Web languages at the end of the day are purely text processing languages. Everything works acting like a string or object/array as Marcus said. This is because all you you normally deal with is strings in your request. Likewise your HTTP response is a string, and what you store in the DB is normally some form of string. a machine level language like C++/C needs typinging more as a string is an "abstract type" as far as a CPU is concerned and as a result if you are dealing with low level control which a machine, you normally need to deal with things like addresses etc etc. The compiler needs to know what types you are dealing with at compile time in order to produce optimised machine code.

    Generally, Type safety should not be an issue in non compiled languages. At the end of the day type safety only adds unneeded overhead when you are dealing with any language that runs on a Virtual Machine as it just means implementing a number of run time checks.

  3. #28
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Grand Rapids
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been very impressed by the look of Rails too, but haven't had a chance to try it out, or do any coding in Ruby. I'm hoping to once I get a few projects out of the way.

    I've used Python for a couple of XML projects and have been very taken with it. I'm hoping better web frameworks appear soon, but will continue to use it regardless.

  4. #29
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Serenarules
    Actually, I think I'll stick with what I know for now.
    It's up to you, but I have always regretted that decision.

    Quote Originally Posted by Serenarules
    Is that any better?
    What are your other development practices? What are you trying to prevent?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  5. #30
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    As in my next to last post, I'm trying to avoid bakruptcy. I simply don't have the time to retool or adapt right now. Afterwards, the future is wide open, but now is not the time to start messing with things. I tried PHP because I was tired of trying to make .NET emulate the eval() method of old or the include() method of PHP. Just like my trying to make PHP emulate .NET's type safety. I don't think either issues was really that important, I was just trading one thing for another. Once again, fighting against the machine. I decided yesterday that I was going to stop that no matter what language I used. Considering my time frame, and my more in depth knowledge of the MS technologies, why not stick to that in order to get this product out the door. I can worry about porting to other languages afterward. It's as simple as that. You guys made me realize what I was doing and why. For that I thank you.

  6. #31
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I've been following this thread from the start, and someone commented that PHP wasn't the langauge for you I believe?

    I tried PHP because I was tired of trying to make .NET emulate the eval() method of old or the include() method of PHP. Just like my trying to make PHP emulate .NET's type safety.
    What I'm starting to see is that this above quote is your problem; You have developed with a number of langauges, now you are trying to duplicate the functionality of one language set to another.

    It doesn't work that way I'm afraid, you've either got to accept a langauge for what it is, or not at all. This you can't accept, from your own admission. The feeling I get is that it doesn't matter what langauge you use, you're going to find fault with it.

    PHP is loosely typed, reasoning is given by a number of members; it's the environment that PHP is, that PHP is loosely typed.

    It's just something you have to live with at the end of the day, really

  7. #32
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think we all understand that concern. Deadline pressures make you do things the easy way, which is sometimes the best way anyway, but sometimes not. For example, I'm just starting to perceive the value of OO and luckily I have some projects I can work on at a leisurely pace to get up to speed on it. But still, when I come up against little website projects for work with tight time allowances, I find myself going back to procedural and just reusing functions I have written long ago that still do the job.

    It's really hard to think about design patterns and abstraction and so on when you're up against it. I spend my weekends "pushing it" on our internal test websites. Personally I think you're making a valid choice.

  8. #33
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    *sigh* Do you guys just like repeating things I just said? That's twice in a row...

    I had already come to the following conclusion Livingston...

    ...fighting against the machine. I decided yesterday that I was going to stop that no matter what language I used. Considering my time frame...
    Consider this too. If had never got the idea in my head that I could make .NET emulate the eval() method effectively, I would've never tried PHP to begin with and this thread would not exist.

    ...the best way anyway, but sometimes not.
    At this point I don't think it's matter of which way is better, rather it is simply getting it to working completion.

  9. #34
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Best of luck to you Serenarules, whichever route you take.

    If you choose not to use PHP for this iteration, I hope you do come back and visit it again later. You have certainly touched off some above average interesting threads here in the forum.

    I few thoughts that crossed my mind while lurking on this thread that I figured I would dump now that I am responding:

    Ruby as a language choice would probably give you fits, the same as PHP, as there is not strong typing in either. There is an interesting concept of "Duck Typing" in Ruby (if it walks like a duck, and it quacks like a duck...). Hosting would likly be a problem with it here (perhaps better in the Japanese market).

    I have no idea what the hosting market for ASP/.NET it, but it seems as if there are more LAMP hosts every day. The free (as in beer) nature of the platform certainly encourages ISPs to provide the hosting for the environment (quality of hosting obviously varies), but I have no ideas about relative growth trends between the two. The fact that I am replying to a post in an Advanced PHP forum should give you a clue where my bias would be if I ventured to guess .

    Regards,
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  10. #35
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had already come to the following conclusion Livingston...
    Sorry about that, I posted reading your last post in reply to that, not knowing that someone else had just beaten me to it

    Hope you find a way of sticking to PHP anyways, and you get the roll out you want on time

  11. #36
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I'll definately revisit it.

  12. #37
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    I was just in the kitchen and had another thought. I'd like to run this by you while I have your attention and see if you have nay advice that might help me overcome something.

    Part of the reason I am having a having a hard time with PHP is because I am used to thinking a certain way. Let's leave rants about stagnation out of this as I am already aware of the concept.

    The way in which I normally develop an application is purely object oriented. The following is offered for those PHP developers who are not familiar with asp.net. With an asp.net page, even the controls on the 'designer' page have properties and events that are mapped to object code. What this means is that I do not have to wait for some line of code in a loop, or a long list of procedural code, to execute, before I know what value to initialize the control with. It has it's own onload function (not client js, rather server code, before the page is rendered). The only 'linear' code I have to deal with is solely within the context of a single function. If designed properly, said function will have only a few lines of code that get straight to the heart of what the function is supposed to do.

    With PHP I seem to get lost, for lack of a better word, when it comes to class design, the final scripts linear code, and how they relate. It seems to me that there are only a few things that even qualify as common code: db connection classes, db select classes, db update classes, input variable (get, post, ...) validation and sanitzers, and output abstraction. The rest would seem better off as linear would it not? That's not what I've been seeing here at SPF the past few weeks though. I've posted in many OOP threads, which I am naturally drawn to as you might expect, and they all lead me to think the opposite? Which of the following is a better example script?

    Code:
    require_once('/includes/initialize.php);
     
    $app = new Application();
    echo $app->DisplayIndex();
    unset($app);
     
    require_once('/includes/terminate.php);
    ...or...

    Code:
    require_once('/includes/initialize.php);
     
    $app = new Application();
     
    // ...some code here...
     
    if ($app->Properties->ShowRecentPosts) {
    foreach ($app->RecentPosts() as $post) {
    // .. do something with it here...
    }
    // ...other code here...
     
    unset($app);
     
    require_once('/includes/terminate.php);
    In other words, how does one properly balance the two idioms? The answer to this may assist me upon my return to full time PHP coding.

    Thanks in advance.

  13. #38
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personal taste I suppose; I would go with the first example

    But what SweatJs said in one thread a long time ago I still remember today is that you will always have, to some extent, procedural script to kick things off.

    I tend to have procedural for fetching a configuration file, extracting the variables, and making a few INCLUDEs.

    After that, it's all Object Oriented Programming as I'm most comfortable with this. If I could (cleanly) encapsulate the parsing of the configuration file and the INCLUDEs, believe me I would do so.

    Hope that helps?

  14. #39
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Quandry then...in sanitizing in put variables I'd like to create a routine that does the following:

    1) creates a single array
    2) sets up a list of "acceptable" keys
    3) iterates through all available system arrays ($_GET, $_POST, $_FILES, etc....)
    4) add only acceptable values to the new array
    5) unset certain system arrays.

    The question is, what order should I look at the system arrays?

    [edit]
    Didn't see you post there Dr....yes it does.

  15. #40
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For your question, I don't suppose it'd make the difference of the order? As to a solution, you need to look at the Chain of Responsibility pattern;

    Also do a search on McGruffs postings, as he's looked at this pattern a lot

  16. #41
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Serenarules
    1) creates a single array
    2) sets up a list of "acceptable" keys
    3) iterates through all available system arrays ($_GET, $_POST, $_FILES, etc....)
    4) add only acceptable values to the new array
    5) unset certain system arrays.
    Sounds like you have the beginings of the spec for a Request object.

    PHP Code:
    class Request {
      function 
    setValidKeys($list) {}
      function 
    get($var) {}
      function 
    getRaw($var) {}
      function 
    getPost($var) {}
      function 
    getCookie($var) {}
      ...

    Could be implemented as a MonoState pattern since you are accessing superglobals through it anyway, but I would just recomend passing it down through the layers of your application. This makes it easier to test your application in general.

    I definitely recommend looking at the practice of unit testing if you have not already, that is possibly the most important programming practice you can adopt.

  17. #42
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    That's exactly what I want. The difference being, in addition to fetching only certain values, unset all others in case a third party mod developer tries to use something outside the scope of the app. This would indeed be a singleton.

  18. #43
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Strong typing does have value in systems that will crash without explanation, such as compiled languages where you have to manage memory, or very long running systems where you cannot test every code path. In fact full on contract tools like Eifel and ContractJ may be needed. I am a big fan of tools that support typing in this environment.
    I believe that the ariane 5 rocket failed because of a bad typecast in a strongly typed language. Sometimes dealing with the exceptions to the rule is worse that the harm the rule is trying to prevent.

  19. #44
    SitePoint Enthusiast siteartwork's Avatar
    Join Date
    Jan 2005
    Location
    Germany
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey folks,

    I recently stumbled over this discussion and want to put my 2 cents on it.

    Since programming with ZE2, I always found letting class type hinting only allow for user created classes is a big hazzle.

    However, I thought about building wrapper classes for primitive datatypes just like Java does. I have written several classes for this purpose, and if one of you shows interest in this I will put em on my webserver for downloading. The documentation is ok, not complete, but I think most of you will get the point pretty fast.

    I personally like the idea of having a String-, Integer- and-so-on class so that type hinting gets more stringent in my applications and doesnt rely on the discipline of the developers using my API.

    On the other hand, there is the overhead produced by creating those Objects - which gets worse if you do not use a bytecode-cache...

  20. #45
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Yeah...I've pretty much abandoned this. Here's the string class in any regard, minus the wrapper functions. Just for the curious...

    PHP Code:
    class CString {
    private 
    $_data;
    public function 
    __construct($value null) {
    if (
    $value instanceof CString) {
    $this->_data $value->value;
    } elseif (
    is_string($value) || is_null($value)) {
    $this->_data $value;
    } else {
    // throw your own 'bad argument' exception here...
    // end if
     
    // end function __construct()
     
    public function __get($name) {
    switch (
    $name) {
    case 
    'value':
    return (string) 
    $this->_data;
    break;
    default:
    // throw your own 'bad property' exception here...
    // end switch
    // end function __get
    public function __set($name$value) {
    $value = new CString($value);
    switch (
    $name) {
    case 
    'value':
    $this->_data $value->value;
    break;
    default:
    // throw your own 'bad property' exception here...
    // end switch
    // end function __set
    public function __toString() {
    return (string) 
    $this->_data;
    // end function __toString
    // end class String 
    At the very least, if one wanted to seperate validation of type with validation of content it could used as an argument checker only...

    PHP Code:
    function Test ($var) {
    $var = new CString($var)->value// would raise exception on fails...
     
    ...your code...

    Anyway, I think I am done with this topic.

    Minor edit...

  21. #46
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Serenarules, I haven't read the whole thread yet, but has anyone suggested that you check out http://go-mono.com ? It's an open source implementation of .NET.

    --ed

  22. #47
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    No, they haven't. Is it something only root can install? Will it handle vb.net language? These two are required *IF* I am even to look at it for a .NET solution.

  23. #48
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Serenarules
    No, they haven't. Is it something only root can install? Will it handle vb.net language? These two are required *IF* I am even to look at it for a .NET solution.
    I haven't played mono myself, I've just read about it.
    I found this though:http://www.go-mono.com/mbas.html

    --ed

  24. #49
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Interesting read. Most of the things they list as "in progress" would be things I'd want now. I see no advantage in that over native .NET. On a side-note, the following appeared in thier page...

    * Events - to a limited extent. You can declare a Class-Field as 'WithEvents' and dynamic events (i.e AddHandler MyButton.Click, Button1_OnClick).

    I recall doing this myself manually in PHP using an extended Observable/Observer class within the past month. I even posted it here somewhere.

  25. #50
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    CA
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couple of things:

    Serenarules, I am interested in your code that you mentioned in your first original post in this thread.

    Mono's advantage is its license, and it is free and supports asp.net. Mono doesn't support vb.net, but you can use one windows machine to use vb.net and deploy your code in mono, since compiled vb.net will work on mono.

    php is trying to move towards .net in a way, but it is still mostly procedural. Check out php 5 which has fantastic new features, which many php programmers still not aware of. PHP 5 still doesn't have namespaces though which is a big problem for people thinking about reusability and scalability (not in performance sense).

    It is quite hard to believe that you are moving away from .net, because of the operating system money, since .net and its basic development tools are free. I would like to hear why exactly the price of the operating system is really important for you. If you hate Microsoft, you don't have to answer it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •