Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Mchl what does "brugere i panik" mean?
  2. Those things the teacher threw at you or hit you with.
  3. interface IProduct { public function getPrice(); } interface IBook extends IProduct { public function getISBN(); } class Book implements IBook { public function getISBN() { return $this->isbn; } public function getPrice() { return $this->price; } } class Client { public function setBook(IBook $b) { echo $b->getISBN(), $b->getPrice(); } } class OtherClient { public function setProduct(IProduct $p) { echo $p->getPrice();//$p->getISBN() is not possible altough I can pass a Book object } }
  4. Really. Do you get paid before 9 and after 5? No. But I have a passion for programming. You also don't get paid for helping people out here and yet many invest a serious amount of time here. Absolutely. You would not have a life if it was. Ok, programming is maybe the wrong word. I mean the actual thing you do after the computer screen and reading books, taking trainings, .. Whenever I take a vacation or go to a conference I stock up on books to read during the flight. Some argue that I'm missing the point of taking a vacation while they are reading books on the beach, before they get to bed, .. Exactly. I created a hangman game recently that made me realize that I actually suck in it Currently I'm working on a Monopoly game and I'm still not winning.. And I'm sure most of the members here spend a serious amount of time developing fun stuff in their spare time for which they won't get paid (~open-source).
  5. How do you then handle 354 + 3? Or is it all separated by a space, but having an Assembler background I don't see how that could work as how would I know I had to read 1 byte, 2 bytes, 3 bytes?
  6. And this is easier then you might think as most employed professionals (at least most of whom I know) still sit-on-top of the (outdated) experience they gained in school and throughout their careers. They only take a training whenever the company think they should (and pays for it)... unbelievable. To me programmers in theory but not in practice. Programming is a way of living not a 9-to-5 job.
  7. Do your store owners share customers? Or should they be separated? I still don't get what you want to achieve with owner_customer_id or do you want to create a concatenation of both the customer_id and owner_id (1,1 => 11)? And why can't they know the system id?
  8. I believe this is Eric's lawn
  9. Just to note that: $q001 == "right" or "right2" works but is not the desired result as this always executes ($q001score = 1) never ($q001score = 0) because "right2" equals to true and because of the nature-of (or, ||) statement (which executes the if-body whenever a, b or both are true)
  10. An interface defines behavior but allows implementing classes to define the implementation. The AuthInterface for example defines isAuth() && login() but does not give the implementation so implementing classes can use sessions, flat-files, sql, .. Because of this you can use interface's as "flags" whenever you see one you know that the passed objects contains those defined methods when they don't a fatal error occurs. An interface and an abstract class can not be instantiated only implemented or extended respectively. The difference between an interface and an abstract class is that the latter can define an implementation and let all others to fall-through (for example if one method is the same for all extending classes). Whenever your wite new SomeClass() you couple it directly to the class which uses it and you will need to go into the source whenever you want some other class to handle it (and if Java re-compile). A factory or a builder allows you to define the implementation at run-time, which means that it can vary (be it SomeClass or SomeOtherClass, even SomeOtherOtherClass). It makes your code flexible. All of these "laws" (software design principles) have one thing in common: to support change (the only true guarantee in software architecture). According to Robert C. Martin [Design Principles & Pattern] a bad design can be identified by 4 factors: Rigidity every change brings along other changes to the system Fragility every change brakes your system Immobility you can't port it to another application without having to alter the code Viscosity easier to go around the problem in your software then to actually solve the problem
  11. I am going to do the same, I am really interested in hearing what fellow members have read (or are reading) and which of these they recommend.
  12. Here's my list again, with links to the actual books on Amazon (to avoid confusion): [*] 97 things every programmer should know [*] Web Engineering [*] Expert PHP and MySQL [*] PHP Pocket Reference [*] Domain-Driven Design [*] Applying UML and Patterns [*] Patterns of Enterprise Application Architecture (PoEAA) [*] Design Patterns [*] Beginning Algorithms [*] Guide to Enterprise PHP Development [*] Object-Oriented Analysis & Design (Grady Booch) I left out all Dutch books and books I wouldn't recommend to anyone.
  13. @oni-kun you must be a wise-man for having lived so long not to mention you survived many, many wars while probably being always the oldest on the battlefield. Did you have the chance to meet General Patton? Did you help build the binary computer to crack Enigma? Did you help build Enigma? You must have some story to tell 23 here And like grim I'm around here since 2005
  14. Are they all hosted with the same provider? If so, you can ask your provider to refer all other 8 domains to your main domain this means that you would no longer have to pay for those 8 servers except domain registration fees
  15. Such a service indeed already exists, there are actually already many out there, for example: www.freelance.com www.project4hire.com www.guru.com
  16. What are you trying to accomplish with that design? How can a customer have an owner? And doesn't (id, owner_id) of a customer already imply owner_customer_id?
  17. It all depends on your host whether you are using a (virtual) dedicated server or shared hosting. Although there are some conventional directory layout's I generally stick to my own: (virtual) dedicated server -------------------------- private_html `- modules `- www ([b]www[/b].domain.com) `- admin ([b]admin[/b].domain.com) `- settings `- www.ini `- install.ini `- libraries `- templates `- scripts `- layout.phtml public_html `- images `- scripts `- styles `- index.php `- sitemap.xml For shared hosting I generally use the same above structure but move everything from private_html to public_html and add the necessary .htaccess files. For my database structure I tend to use: - plurals for database tables - singulars for all fields including FK - if the table is specific to a certain part of the system I prefix it for example: forums, forums_topics If you go through Google you'll find some good naming conventions for your database tables, field names, .. @thorpe where did he mention the use of OOP? The OOP principles (the more popular one's) thorpe is referring to are: - program to an interface, not an implementation - favor object composition over object inheritance SOLID: Sinlge Responsibility Principle (SRP): Every class should have only one responsibility for example User, Zend_Auth all serve just one purpose Interface Segregation Principle (ISP): this means that you should make your interfaces cohesive, group by functionality, for example you can instantly see that something here is wrong: interface AuthInterface { public function login(); public function isAuth(); public function getProducts(); } getProducts() is here clearly not the responsibility of AuthInterface and any class implementing this interface has the unnecessary overhead of getProducts() Open-Closed Principle (OCP): open for extension but closed for modification, in practice this applies to interface's (see ISP) but can also apply to classes that you have used in previous projects (do not mess in their source, extend them) Liskov's Substitution Principle (LSP): MyClass mc = new MyClass(); should be: MyParentClass mc = new MyClass(); the use new MyClass(); is also bad as in whichever class you did use this you made it tightly coupled and a factory would be better: MyParentClass mc = MyParentClassFactory.factory(..);//basically you now can use any child of MyParentClass try to go as high as possible (interface) but make sure that all required functionality is covered, the following example is wrong: interface MyInterface { public function doSomething(); } abstract class MyAbstract { public function doSomethingElse(); } MyInterface mi = SomeFactory.getClass(); mi.doSomethingElse();//guarantee that your code will break at some point Dependency-Inversion Principle (DIP): stirred up some serious discussion a while back. This means that you should pass collaborators (class members) as parameters public function __construct() { $this->object = new Object(); } public function __construct(ParentObject $o) { $this->object = $o; }
  18. You don't necessarily need a temporary table if you go through the preview process you'll notice that below the preview it contains the previous form. So, basically something like this would work: <input type="submit" name="preview" value="Preview"> <input type="submit" name="save" value="Save"> if (isset($_POST['preview'])) { print_preview($_POST); } if (isset($_POST['save'])) { //insert into database } //form
  19. ClassName::IsClientLoggedIn() add static public static function IsClientLoggedIn()
  20. He's using == so "", 0, 0.0, "0", array(), null should all pass myfunction() == false
  21. function readCsvFile($csvFile) { if (!file_exists($csvFile)) return array(); return array_map('csv2array', file($csvFile, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES); } function storeCsvLine($line, $csvFile, $mode = FILE_APPEND) {/* @see php.net/file_put_contents */ if (!file_exists($csvFile) || (!is_string($line) && !is_array($line))) return 0; if (is_array($line)) $line = implode(',', $line); return file_put_contents($csvFile, $line . PHP_EOL, $mode); } function csv2array($csv) { return array_map('trim', explode(',', $csv)); } function readProducts($file) { return readCsvFile($file); } function readCart($userId) { return readCsvFile($userId); } function storeProductInCart($product, $userId) { return storeCsvLine($product, "$userId.txt"); } function getCartSubTotal($userId, $cartContents = array()) { if (empty($cartContents)) $cartContents = readCart($userId); return array_reduce($cartContents, 'getCartSubTotalCallback'); } function getCartSubTotalCallback($item1, $item2) { return $item1[2] + $item2[2]; } function get($offset, $default = null) { return isset($_GET[$offset]) ? $_GET[$offset] : $default; } session_set_cookie_params(86400);//1-day session_start(); if (get('action') === 'show-products') { include('show-products.php'); /* $products = readProducts('path/to/products.txt'); */ } else if (get('action') === 'show-cart') { include('show-cart.php'); /* $cart = readCart(session_id()); $cartSubTotal = getCartSubTotal(session_id()); */ } else if (get('action') === 'add-product') { include('add-product.php'); /* $product = array(post('product_name'), post('product_no'), post('product_price')); storeProductInCart($product, session_id()); */ } Should give you a good start The comments below the include in the second example are a sample implementation. These belong in one file I separated them for easier reading. Give your teacher my regards
  22. He asked for things that are worth the money not to just spend the money
  23. I generally spend my money (whether or not tax returns) on books (and the occasional training). My current stack: Design Patterns, Erich Gamma Patterns of Enterprise Application Architecture, Martin Fowler Applying UML and Patterns, Craig Larman Domain-Driven Design, Eric Evans PHP Pocket Reference, Rasmus Lerdorf Expert PHP & MySQL, A. Curioso Web Engineering, ICWSE Conference Spain 97 things every programmer should know, Kevlin Henney & Adrian Wible (with help from Robert C. Martin amongst others)
  24. You always have a NS specific to your domain regardless of your type of hosting. The A-record contains an IP-address and you shouldn't care about that. Where are your other 8 domains hosted? Are they hosted on a separate shared hosting?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.