1. OT : Eu and OOP - why it should never be (an opinion)

Hi

Came across this the other day - says what I think more eloquently tha I could otherwise express.

https://medium.com/codeiq/object-oriented-programming-the-trillion-dollar-disaster-%EF%B8%8F-92a4b666c7c7

Cheers

Chris

new topic     » topic index » view message » categorize

2. Re: OT : Eu and OOP - why it should never be (an opinion)

"Never" is a pretty strong word.

If this article were in favor of procedural programming (like Euphoria) over heavy object-oriented programming (like Java) then I'd be on board. But the author is just a shill for Erlang and functional programming. I dislike functional programming, but I'll admit that may be because I've met one too many evangelical functional programmers who think they've found the next holy grail.

I used to think "object oriented" was just a particular style of coding, and I disliked it because it could create huge unmaintainable code bases. Turns out it's a particular set of patterns and practices that don't restrict the programmer to any one language or coding style. I hate Java and its entire ecosystem (it's huge, bloated, and angry. fight me), and I tolerate C# and Python because they're widely supported in the industry, but none of those are what make up object-oriented programming per se.

There's a lot of object-oriented patterns I've implemented in Euphoria MVC. They may not look like it on the surface, but that's what they are by definition and practice.

The database engine is a prototype pattern: you can register different types of database handlers and then use any of them from a single interface.

-- mvc/db_mysql.e 
include mvc/database.e 
 
constant MYSQL = add_protocol( "mysql" ) 
 
function _connect( sequence url, integer timeout ) 
    -- do connect stuff here 
end function 
add_handler( MYSQL, DB_CONNECT, routine_id("_connect") ) 
 
function _query( atom mysql, sequence stmt, object params ) 
    -- do query stuff here 
end function 
add_handler( MYSQL, DB_QUERY, routine_id("_query") ) 

Example:

object conn = db_connect( "mysql://user:password@host/database" ) 
 
atom result = db_query( "SELECT * FROM users" ) 
if result then 
 
    sequence row = db_fetch( conn, result ) 
    while length( row ) do 
 
        row = db_fetch( conn, result ) 
    end while 
 
end if 
 
db_disconnect( conn ) 

The model engine is a factory pattern: you can register models and then create, read, update, and delete (CRUD) them.

-- define a "user" model 
constant USER = model:define( "user", { 
    { "id",         AUTO_INCREMENT }, 
    { "name",       TEXT }, 
    { "email",      TEXT }, 
    { "manager_id", INTEGER } 
}) 
 
-- John's manager is Bob 
object manager = model:find_one( USER, "name='%s'", "Bob Jones" ) 
integer manager_id = model:get( manager, "id", 0 ) 
 
object user = model:new( USER, { 
    { "name",     "John Smith" }, 
    { "email",    "john@example.com" }, 
    { "manger_id", manager_id } 
} ) 
model:store( user ) 

Heck, since I'm on about functional programming, the template parser would qualify as this. Each function is built to be independent and only rely on its input to create its output. You feed it a template and some values, and it goes to work parsing the template and re-assembling it around the data, without any side-effects or global state*.

*A couple caveats to this: currently, template functions are stored in a global map, and there is a global map for caching parsed templates. This could be moved into the response object, or make it an exercise for the user to pre-parse cache their templates if they want. I could rework it to make this purely functional, but it's easier to use as-is.

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: OT : Eu and OOP - why it should never be (an opinion)

ChrisB said...

Hi

Came across this the other day - says what I think more eloquently tha I could otherwise express.

https://medium.com/codeiq/object-oriented-programming-the-trillion-dollar-disaster-%EF%B8%8F-92a4b666c7c7

Cheers

Chris

It is the best article I have read about why I should not even bother about OOP. I have no reason now to even look at OOP, and will be content with what we have. Eu is simple and I can create applications very fast. I have been using wxEuphoria with Eu 4.0.5 and I have several modules ready, so a small software assignment can be executed in 2-3 days and I can charge for 3 weeks equivalent of time.

new topic     » goto parent     » topic index » view message » categorize

4. Re: OT : Eu and OOP - why it should never be (an opinion)

I'm not a fan of OOP. I dislike it. Even when I use Cplus plus, I tend to use a more C like style. OOP is just more code for the same effect. Euphoria is great, no OOP. Though Euphoria could benefit from something like C's structs, which has been discussed before.

new topic     » goto parent     » topic index » view message » categorize

5. Re: OT : Eu and OOP - why it should never be (an opinion)

ChrisB said...

Hi

Came across this the other day - says what I think more eloquently tha I could otherwise express.

https://medium.com/codeiq/object-oriented-programming-the-trillion-dollar-disaster-%EF%B8%8F-92a4b666c7c7

I've got that same article in my ToRead list! I've been seeing a lot of that kind of report lately. smile

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu