Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. I believe this is Eric's lawn
  2. 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)
  3. 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
  4. 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.
  5. 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.
  6. @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
  7. 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
  8. Such a service indeed already exists, there are actually already many out there, for example: www.freelance.com www.project4hire.com www.guru.com
  9. 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?
  10. 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; }
  11. 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
  12. ClassName::IsClientLoggedIn() add static public static function IsClientLoggedIn()
  13. He's using == so "", 0, 0.0, "0", array(), null should all pass myfunction() == false
  14. 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
  15. He asked for things that are worth the money not to just spend the money
  16. 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)
  17. 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?
  18. Some good advice. I generally try to learn and explore multiple languages in one area/group (web for example) and adjust according to the project requirements although I'm biased towards free, open-source languages. You will not easily find me learning a language that isn't open-source.
  19. Why not use a database instead of .txt files, a database is much faster not to mention cleaner.
  20. Not to sound, mean, but I use that exact code for my boards on my website. e.g. You posting a reply on here, you hit enter button, it supplies a "<br>"... And it works for every browser, not just some... Which is why I use it... Yes on your Windows machine. Now, try that on Linux and Mac and see if that still works
  21. That \n indeed did the trick but you used the wrong editor to open it, notepad requires \r\n
  22. If you have DNS access then you can change the Name Server setting to your NS of your main server. If they are all hosted on the same server you can adjust the CNAME settings so that all 8 domains refer to your main domain something like: www.main-domain.com A 10.0.0.1 www.main2-domain.com CNAME www.main-domain.com www.main3-domain.com CNAME www.main-domain.com .. Personally I use the latter to refer subdomains and I'm not entirely sure this also works for entire domains.
  23. This will only work if his editor used the same line breaks as the user's browser did (in your code) for example: $news = "This is my news.\nHey there!\nThanks buddy! =)\nHi!";//assume from $_POST echo str_replace("\r\n", "<br />", $news);
  24. That is not possible with the above CSS rules it's most presumably some other line that does that which is not shown in the above example as the rule that includes the *-character tells the browser to apply width: 99px on all elements that has a child-element HTML that has a child-element with class .faculty-img which is none as no element contains the root element. * html .faculty-img therefor should be .faculty-image Also class="/faculty-image/" is incorrect and should be class="faculty-image"
×
×
  • 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.