Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Proper way to create packages and re-usable code?

by Anonymous Monk
on Feb 11, 2016 at 09:38 UTC ( #1154930=note: print w/replies, xml ) Need Help??


in reply to Re: Proper way to create packages and re-usable code?
in thread Proper way to create packages and re-usable code?

A little related commentary

Is ZXappz::Logger that uses log4perl and ZXappz::Database will load DBI

:) That is one of those weird things that don't quite make sense

log4perl and DBI both provide good APIs that they don't need generic wrappers

Now if you're talking a static "Config" module or a "Model" module, that makes sense, but not a generic logger/database, log4per/DBI are already that generic module, just configure them and you're done

Yeah, sometimes it makes sense to have a generic logger/database module as part of your API, but I'd say most of the time it doesn't :) its weird :D

  • Comment on Re^2: Proper way to create packages and re-usable code?

Replies are listed 'Best First'.
Re^3: Proper way to create packages and re-usable code?
by Discipulus (Abbot) on Feb 11, 2016 at 09:52 UTC
    Ok, stated my limited experience, i just only to say that probably you need ZXappz::Database anyway because it can contains for example store_new_user and store_action_for_user and so on. So in the main code you can just:
    my $appdb = ZXappz::Database->new(); $appdb->store_new_user($previously_generated_name,time); # uses DBI to + insert into a table .. $appdb->close # call the DBI's close but maybe also log somewhere the +succesfull operation

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      ZXappz::Database anyway because it can contains for example store_new_user and store_action_for_user and so on...

      :) That is good thinking, separate the stuff, groupt the database stuff together

      but the name should be different from "database" because that is kind of stuff that goes in your "model",

      so you might have a ZXappz::UserGroup (or ZXappz::Model::UserGroup) with a add_user and ...

      yes it goes in a database, maybe one created from ZXappz::Schema::UserGroup ...

      but you call it something important to your app, symbolic not generic

      Its like when you first learn programming, no subroutines, just long stretches of code, you have to start somewhere

      then the next evolution, you start using subroutines, but its still one file, and they're very long and do too much, and the names are focused on the implementation details

      then you start making packages, which is great, but you're organizing principle is not the intent of the code but implementation detail;

      Is this terrible? No. Its common, its workable, its maintainable, esp for short programs, but could be improved; and should be improved , esp if you want to reuse the code, and for others to use your code , and enjoy it (collaboration )

      There is no reason to take the long way around, jump straight to intent :) organize stuff with big picture in mind, like a house, you have to frame it, but you don't design around the frame, around stud, you design around rooms with purpose, by walking around the house in your head, wake up in the morning, get ready for work, host a party...

      start with a story board, how should the user use the application, what should it do

      then start with use cases, how should the code be used by the programmer, write that code, and your api will emerge

        thanks Anonymous Monk i hope i've caught the sense of your words. My programming vocabulary lacks of right definition for words like Model and Schema but, yes i think i got it.

        I'll be even more sure if you can delucidate me about the sentence :"but you're organizing principle is not the intent of the code but implementation detail;"

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154930]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-05-17 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?