Page 1 of 1

Advanced: Code Reuse, Classes, and CVS Systems

Posted: Sat Jul 07, 2007 11:38 pm
by ThePCNerd
Thanks for checking this topic out, as I am in need of some help, guidance, and assistance to further my development skills.

Outline
1. Intro
2. Admission of Inferiority
3. Code Re-Use
4. Classes and Application
5. CVS
6. Security and E-Commerce


Intro/Bio:
This intro helps place you in my situation; I'm sure many of you were here a couple years ago. I'm 19 and live in Florida. I've worked on the LAMP platform for 3 years, built websites for 7 years, and programmed since age 7. I make pretty good money building websites in my own manner, developing CMS's individually, becoming more secure each one I develop. Finally I am now finding myself taking on bigger responsibilities with each project, slowly delving deeper into e-commerce. I work as a private contractor for a company, who provides a bunch of simple projects mainly for aiding in client independence and upkeep minimization.

Admission of inferiority:
I am an amatuer, I have built some impressive work, but I'm entirely sure there are a million things for me to learn in web development and for that matter any programming. Thats why I've come to these forums, that's why you are reading. I'm sure my conventions for re-using code and many other things are trivial compared to yours. So please, help me out here.

Code Re-use:
I've seen code library applications, but I can't really make effective use of them. Re-using code consists of remembering where I wrote a certain function or process line, then finding it and copying it over to my new app.

Classes:
I understand OO relatively well, I programmed in Java for a year in a class. I don't use classes in my PHP development and I know I should but I can't think of a good way to implement them.

CVS and other Multiple Developer Platforms
I don't know how to use a CVS / Multiple Developer Platform. I honestly want to contribute to Open-Source projects, but I don't even know how to get started. It seems like it's an invite-only croud to me, keeping me away from it.

Developing Secure, and Legal E-Commerce Websites
Visa has guidelines that require certification of e-commerce solutions through verification companies. How do these work, and what are the costs? Do they want my source code?

I have that feeling in the back of my head that I'm flamebait by asking so many questions trying to become a professional, but I thought it was worth a try.

Recently I've had thoughts that the projects I'm building are far too easy for my capability and that I need to move on to more difficult situations. Joining the military after college to see some real technological issues and computing sounds ideal especially with all of those Future Combat System videos and specifications. I'm looking for a challenge in the world of business websites that want "guest books to collect contact information from buyers" rather than "An all-inclusive e-commerce website where buyers can analyze and purchase my products readily from the around the world while maintaining simplicity in the order processing, management, and financing departments."

Anyway, thanks for reading, if you did. You'll find me around the forums, I have a lot to contribute in Content Management Systems, Invision Board Integration, AJAX, Flash, Security and Cookie Management.

Posted: Sun Jul 08, 2007 6:56 am
by superdezign
E-commerce and getting into open-source aren't thing I can shed much light on. However, classes and code re-use go hand in hand.

You should make your classes generic, and then inheritance the generic properties into a more specific class, and continue until it's completely site specific (actually, you don't want the classes themselves to be 'site-specific', but allow it to mold easily to your site) and everything before it could be used in a separate website. Every class you make will have a role or a purpose in the scheme of things. The best class to help you get into the mindset of OO in PHP is a database class.

The database class requires functions for connecting, querying, and retrieving results. Sometimes, you'll need a lot of things from results such as the query that was used on them, errors resulting from them, or their result set. So, you'd have an object that stood as the result as well. And, if you wanted to make your error handling better, you'd have a class for errors. So, if you had all three, your database class would have a GetLastError() function that called the GetError() function of the result object which calls the GetErrorMessage() function of the error object which is then sent all the way back to the database object which could echo the data, log it, etc.

OO is about separation of duties. It also keeps everything organized, and keeps the code that uses the classes looking clean and easily modifiable.

Re: Advanced: Code Reuse, Classes, and CVS Systems

Posted: Sun Jul 08, 2007 8:58 am
by The Phoenix
ThePCNerd wrote:I've seen code library applications, but I can't really make effective use of them. Re-using code consists of remembering where I wrote a certain function or process line, then finding it and copying it over to my new app.
Copy/pasting gets a bad rap, although for somewhat valid reasons: Bad code reused means far more bad code. Since it is done more by less experienced programmers, it tends to bias to bad code reuse.

However, it *is* reuse in its most basic form, and if you reuse good code, thats a good thing. Going the next step to realize that you reuse a chunk of code, and rewrite it to be more easily reusable in a number of situations is a natural evolution. Then moving from there into a chunk of code with distinct inputs and outputs, with a formal structure for interfacing with it leads to classes. Finally adding testability via unit tests is also a natural extension of the process. Some people do it in a different order, but the spectrum is relatively consistent.

Don't feel frustrated if you haven't made it past step 1. Just look for areas where going beyond step 1 might be helpful, and eventually you'll do so. Forcing yourself into a programming method that doesn't give *you* obvious benefit is a good way to get bitter about it. (And it may be a sign its not the right solution anyway!)
ThePCNerd wrote:I understand OO relatively well, I programmed in Java for a year in a class. I don't use classes in my PHP development and I know I should but I can't think of a good way to implement them.
Two paths to take to get to classes easily:

1. Only add to your program if you can manage a data item as an object. Want to add a login? Thats a "user" object, with a check for its authentication property. Take the object, and make classes that relate to it.

2. Refactor. Take procedural code, and move it into a function with a defined input, and a defined output. Refine it until you have a solid and consistent method for interacting with it. Then change it from a function to a class, and make a unit test for the class. Its loosely coupled to the data, but it is a class, which allows for documented interfaces.
ThePCNerd wrote:I don't know how to use a CVS / Multiple Developer Platform.
You need to know exactly three commands in CVS or SVN to contribute effectively:

1. svn co (Subversion Checkout) - This gets you the tree (pile of code) of the project. Step one.
2. svn update - This updates your tree to the latest version, if changes have been made since you did a checkout.
3. svn commit - This commits the changes you have made to the central tree, allowing others to have access to it.

Those are the actual commands, and their use. Very simple. There are others, to be sure, and you may run into a need for them. But in almost every major project, there is someone on the team that knows it well, and can help with those fairly rare situations.
ThePCNerd wrote: I honestly want to contribute to Open-Source projects, but I don't even know how to get started. It seems like it's an invite-only croud to me, keeping me away from it.
Thats definitely not the norm. Most open-source projects welcome others. A great way to start is to find a project you like. Use that project, and find bugs. Document the bugs, and submit the bug report. That way, you know how the team tracks bugs, and get familiar with the testing process.

You've also started a conversation: You get to talk to a developer and find out how they approach bugs. Maybe they jump on it immediately, and throw in a stop-gap kludge. Maybe they take their time and develop 'the right way' to fix it, which could require a rewrite, or even redefining an interface. In either case, you've got a window into their development style.

Then you can go a step further. Develop a patch that fixes the issue for you. Note, that doesn't mean it fixes it for THEM. Many projects are deployed on a wide variety of platforms with annoying gotchas that are hard to test. As a result, your fix may not be a complete fix for the deployments they have. But don't sweat it! The project will likely rework it to a complete solution. A chunk of working code is often far more compelling than a blank page, and a bug report that says "its broken". Even if they have to tweak it a bit, its a jump start.

Worst case scenario, if you don't find a project you feel values your input, start your own and do it differently!
ThePCNerd wrote:Visa has guidelines that require certification of e-commerce solutions through verification companies. How do these work, and what are the costs? Do they want my source code?
Generally, yes. They want to evaluate both the code, and the way it reacts to outside behavior. ie, do you trust user input.

Its expensive, tedious, and takes a long time. But security is a process. Remember that you have to get *everything* right, and an attacker only has to find one thing you did wrong to get in. Your abilities have to be substantially better than the attackers.

Posted: Sun Jul 08, 2007 9:40 am
by Oren
If you want to join a cool new PHP open source project, you can join us (the guys here on PHPDN) and help us with our DevnetStore project - it's an open source e-commerce.

Re: Advanced: Code Reuse, Classes, and CVS Systems

Posted: Sun Jul 08, 2007 12:28 pm
by alex.barylski
ThePCNerd wrote:I am an amatuer, I have built some impressive work, but I'm entirely sure there are a million things for me to learn in web development and for that matter any programming. Thats why I've come to these forums, that's why you are reading. I'm sure my conventions for re-using code and many other things are trivial compared to yours. So please, help me out here.
Actually, if your making money from software development, by definition, your a professional. :)

Like you, I started programming around age 7. I never did take much in terms of school, as I always figured I knew better than my teachers anyway (something I still stand behind). It's about the only industry where you can get by without a post secondary and still claim to be "professional" assuming you have a reference list of clientèle.
ThePCNerd wrote:I've seen code library applications, but I can't really make effective use of them. Re-using code consists of remembering where I wrote a certain function or process line, then finding it and copying it over to my new app
Shake that mentality ASAP. Although code re-use at any level is good, you should keep a database of simple code snippets if you find yourself reusing code at that level. Personally I can never be bothered reusing a few lines, it's faster for me to hammer them out then copy-paste (except for fragments which are stored in my editor).
ThePCNerd wrote:I understand OO relatively well, I programmed in Java for a year in a class. I don't use classes in my PHP development and I know I should but I can't think of a good way to implement them.
This may sound harsh, but in truth it's probably best. Don't use OOP if your only relatively "well". Relative to what? Relative to the people who claim to know OOP but have no idea as to the importance of polymorphism or OO principles?

If you don't know OOP you can actually write worse code using classes than you can with functions alone. Deeply nested nasty hierarchies, crazy class dependencies, etc. It will actually make your code *much* more difficult to maintain than using functions. Not saying don't use OOP just learn it well before you do.
ThePCNerd wrote:I don't know how to use a CVS / Multiple Developer Platform. I honestly want to contribute to Open-Source projects, but I don't even know how to get started. It seems like it's an invite-only croud to me, keeping me away from it.
As a single developer you can get away with that, although I would recommend using SVN still. It's nice to have perpetual undo for important milestones in your project. As for open source. Look at sourceforge:

http://sourceforge.net/people/

Or, start your own. ;)
ThePCNerd wrote:Visa has guidelines that require certification of e-commerce solutions through verification companies. How do these work, and what are the costs? Do they want my source code?
Number one rule of eCommerce is don't bother with eCommerce. There are so many different projects to work on, why eCommerce? If you must work on a shopping cart, forget about signing up for a Merchant account and processing CC's through your bank directly. Not only does it cost an arm and a leg, it's riskly business unless you have money to bail you out.

Visa or Mastercard (maybe both) have a policy (at least when I tried a few years back) where if *any* of your customers claim to have not made a purchase, Visa or MC will refund them at your expense!!! Ontop of the monthly fee's and worries about CC storage, etc. It's waaaaaaaaay easier to just go with a third party provider such as PayPal or WorldPay.

At last check PayPal offered the ability to use their API directly so you could avoid having to redirect to Paypal.com for actual processing. This was the case for the US and Canada anyways, probably even more broad now.
ThePCNerd wrote:Anyway, thanks for reading, if you did. You'll find me around the forums, I have a lot to contribute in Content Management Systems
Groovy. Enterprise management systems are my personal forte as well. ;)

Re: Advanced: Code Reuse, Classes, and CVS Systems

Posted: Mon Jul 09, 2007 9:05 am
by kyberfabrikken
Hockey wrote:
ThePCNerd wrote:I don't know how to use a CVS / Multiple Developer Platform. I honestly want to contribute to Open-Source projects, but I don't even know how to get started. It seems like it's an invite-only croud to me, keeping me away from it.
As a single developer you can get away with that, although I would recommend using SVN still. It's nice to have perpetual undo for important milestones in your project.
My sentiments exactly. I used to develop without repository for a long time, since I usually was single developer or working on small teams. After I started using SVN, I couldn't think of developing anything without it. Simply for having the unlimited undo capacity.

Posted: Mon Jul 09, 2007 9:26 am
by Chris Corbyn
I start all of my projects with a "svnadmin create repository_name" but I just run it off my VDS server over SSH. It's just so easy for me to come to work, get bits and pieces of personal stuff done in my lunch break, commit changes, carry on at home. I also manage my Java servlet deployment with subversion locally too. Like someone else just mentioned, it's like a constant "undo" :) I notice Apple are adding "Time Machine" to Leopard which has caused a bit of a stir, yet at the end of the day it's just a glorified version control system.

Posted: Mon Jul 09, 2007 10:00 am
by matthijs
I start all of my projects with a "svnadmin create repository_name" but I just run it off my VDS server over SSH.
So this is a remote repository. Does it work a bit fast over SSH?

Do all of you do that? Work from a remote repository (on a server somewhere, Googlecode, sourceforge) and then checkout to a local work copy to develop and test? (and update to the remote repo again when you're finished changing)

Posted: Mon Jul 09, 2007 10:06 am
by Chris Corbyn
matthijs wrote:
I start all of my projects with a "svnadmin create repository_name" but I just run it off my VDS server over SSH.
So this is a remote repository. Does it work a bit fast over SSH?

Do all of you do that? Work from a remote repository (on a server somewhere, Googlecode, sourceforge) and then checkout to a local work copy to develop and test? (and update to the remote repo again when you're finished changing)
I've never found WebDAV to be very fast with SourceForge or GoogleCode. It's a bit faster on our dedicated dev servers at work though, but getting it to work with HTTPS is a pain in the ankle. I only use SSH because it's secure (I obviously already have a shell account) and it's fast. If you wanted to do that with Windows I think you'd need to use Cygwin but fortunately I never have to use windows to develop.

Checking out is a bit odd because you usually get asked for your SSH password 2 or 3 times in a row, but beyond that it's plain sailing, apart from having to enter your password each time you commit:

Code: Select all

svn co svn+ssh://server/svnroot/repos project-name

Posted: Mon Jul 09, 2007 10:17 am
by feyd
PuTTY on Windows for SSH is a lot easier than installing Cygwin. But I digress.

Version control is a really good idea for the singular developer, and a must for groups.