Re: An illuminating experiment using platform().

new topic     » goto parent     » topic index » view thread      » older message » newer message
Shawn Pringle B.Sc. said...

There is absolutely no branching cost of using platform() rather than ifdef when translating to C.

Yes, when translating there is no cost, however, platform() is used in interpreted applications as well. In addition the ifdef system does things platform() could not touch. For example:

while next_line() do 
    ifdef DEBUG then 
        printf(1, "Processing line: %s\n", {line}) 
    end ifdef 
 
    -- normal code 
end while 

Now, here is the code that the interpreter or translator sees when running...

$ exu -D DEBUG myprog.ex 

while next_line() do 
    printf(1, "Processing line: %s\n", {line}) 
 
    -- normal code 
end while 

$ exu myprog.ex 

while next_line() do 
    -- normal code 
end while 

Notice this works on something that has nothing to do with platform(). Also notice it works in the interpreter or translator.

Now, further ifdef can do things like this:

ifdef EU400 then 
    export function super_41_function() 
        return 10 
    end function 
end ifdef 

This is a 4.1 Euphoria application that maintains backward compatibility with 4.0. It's assuming that the function super_41_function() was added in 4.1 and did not exist in 4.0. The uses of ifdef are vast compared to the very limited usefulness of platform(). Further, platform() is generally flawed when it comes to dealing with Linux and FreeBSD. Why? Because they are not the same. FreeBSD has a set directory structure that Euphoria apps should pay attention to. It could enable the use of different FreeBSD facilities, etc... Even DLL loading is slightly different on FreeBSD than Linux. The ifdef handles these types of checks much better than platform()...

ifdef FREEBSD then -- FreeBSD ONLY 
elsifdef LINUX then -- Linux ONLY 
elsifdef OSX then -- OS X ONLY 
elsifdef WIN32 then -- WIN32 ONLY 
elsifdef DOS32 then -- DOS32 ONLY 
end ifdef 

Now, what if you just want to know if you should use cp or copy ? Easy.

ifdef UNIX then -- FreeBSD, Linux or OS X 
else            -- Right now only DOS32 or WIN32 
end ifdef 

Now, if that is not enough, you can define your own words to accomplish all sorts of tasks.

function save() 
    ifdef SHAREWARE then 
        if record_count = 100 then 
            alert("You have reached the limits of the shareware version") 
            return 0 
        end if 
    end ifdef 
 
    -- Save the record 
end function 

So, when you bind or translate your app for shareware versions, it contains limits. Or maybe it doesn't contain features:

ifdef not SHAREWARE then 
     -- feature that is not in shareware version 
end ifdef 

This totally prevents someone from hacking your shareware version because there are no features to hack! That's just an example. Now, you could also do things such as:

ifdef SAFE then 
    include safe.e 
else 
    include machine.e 
end ifdef 

Or, how about choosing a database include?

ifdef PGSQL then 
    include pgsql.e as db 
elsifdef MYSQL then 
    include mysql.e as db 
elsifdef SQLITE then 
    include sqlite.e as db 
end ifdef 
 
db:conn db_con = db:open("host=localhost name=mydb") 
db:query(...) 
db:close(db_con) 

Which is exactly what I do right now, I have pgsql.e, mysql.e and sqlite.e that expose the identical interface, thus, I have a Euphoria app that can run any db I want. The possibilities are endless if ifdef and platform() has no advantage over ifdef. Oh, and in case you are thinking shrouded apps, I think we have a way that ifdef will work just fine in shrouded apps as well.

So, why use platform()? I have no clue.

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu