Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 85

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 85

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 85

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 85

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
[Book] Clean Code: A Handbook of Agile Software Craftsmanship
Results 1 to 10 of 10

Thread: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

  1. #1

    [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    This is a book a friend recommended to me, and so far it has helped me a lot with my coding methods and styles.

    This book is focused around teaching you to write clean, small code that can be easily understood by any programmer who reads it. If you're going to skim this book, don't bother. You'll only disagree with half of what you read and misunderstand everything else. However, if you actually want to better your programming and take the time to read it, you will probably learn a lot.

    I'm currently starting on Chapter 9, been reading 1 a day.

    Using teachings from this book, I've turned this (admittedly old, messy, pasted, and rushed) code

    [code=c++]#include "StdAfx.h"
    #include "Hook.h"

    Hook::Hook(DWORD HookAddress, DWORD NewFunction)
    {
    HookAtAddress = HookAddress;
    OldFuncAddress = HookAddress;
    NewFuncAddress = NewFunction;
    }

    void Hook::Enable(){
    DWORD dwOldProtect, dwNewProtect, dwNewCall;
    //CALL opcode = 0xE8 <4 byte for distance>
    BYTE callByte[5] = {0xE8, 0x00, 0x00, 0x00, 0x00};

    //Calculate the distance
    dwNewCall = NewFuncAddress - HookAtAddress - 5;
    memcpy(&callByte[1], &dwNewCall, 4);

    VirtualProtectEx(GetCurrentProcess(), (LPVOID)(HookAtAddress), 5, PAGE_READWRITE, &dwOldProtect); //Gain access to read/write
    memcpy(&OldFuncAddress, (LPVOID)(HookAtAddress+1), 4); //Get the old function address for unhooking
    memcpy((LPVOID)(HookAtAddress), &callByte, 5); //Hook the function
    VirtualProtectEx(GetCurrentProcess(), (LPVOID)(HookAtAddress), 5, dwOldProtect, &dwNewProtect); //Restore access
    }

    void Hook:isable(){
    DWORD dwOldProtect, dwNewProtect;
    BYTE callByte[5] = {0xE8, 0x00, 0x00, 0x00, 0x00};

    memcpy(&callByte[1], &OldFuncAddress, 4);

    VirtualProtectEx(GetCurrentProcess(), (LPVOID)(HookAtAddress), 5, PAGE_READWRITE, &dwOldProtect);
    memcpy((LPVOID)(HookAtAddress), &callByte, 5);
    VirtualProtectEx(GetCurrentProcess(), (LPVOID)(HookAtAddress), 5, dwOldProtect, &dwNewProtect);
    }

    Hook::~Hook(void)
    {
    }[/code]

    Into this:
    [code=c++]#include "Hook.h"
    #include "memoryHelper.h"

    Hook::Hook(DWORD hookAddress, DWORD newFunction)
    {
    this->hookAtAddress = hookAddress + 1; //The first byte is the 0xE8 for the call, we want to write the 4 after it
    this->newFuncAddress = newFunction - this->hookAtAddress - 5;

    memoryHelper::allowOPCodeModification(this->hookAtAddress, 4);
    this->oldFuncAddress = memoryHelper::getDWORD(this->hookAtAddress);
    memoryHelper::disallowOPCodeModification(this->hookAtAddress, 4);
    }

    void Hook::enable()
    {
    this->setCall(this->newFuncAddress);
    }

    void Hook::disable()
    {
    this->setCall(this->oldFuncAddress);
    }

    void Hook::setCall(DWORD calladdress)
    {
    memoryHelper::allowOPCodeModification(this->hookAtAddress, 4);
    memoryHelper::setDWORD(this->hookAtAddress, calladdress);
    memoryHelper::disallowOPCodeModification(this->hookAtAddress, 4);
    }[/code]
    [code=c++]#include "memoryHelper.h"

    DWORD memoryHelper::getDWORD(DWORD address)
    {
    return (DWORD)memoryHelper::getData(address, 4);
    }
    void* memoryHelper::getData(DWORD address, DWORD size)
    {
    void* copied;
    memcpy(&copied, (LPVOID)(address), 4);
    return copied;
    }

    void memoryHelper::setDWORD(DWORD address, DWORD value)
    {
    memoryHelper::setData(address, (LPVOID)value, 4);
    }
    void memoryHelper::setData(DWORD address, void* value, DWORD size)
    {
    memcpy((LPVOID)(address), value, size);
    }


    DWORD memoryHelper::allowOPCodeModification(DWORD address, DWORD size)
    {
    return memoryHelper::setRegionProtection(address, size, PAGE_READWRITE);
    }
    DWORD memoryHelper::disallowOPCodeModification(DWORD address, DWORD size)
    {
    return memoryHelper::setRegionProtection(address, size, PAGE_WRITECOPY);
    }
    DWORD memoryHelper::setRegionProtection(DWORD address, DWORD size, DWORD protection)
    {
    DWORD dwOldProtect;
    VirtualProtect((LPVOID)(address), size, protection, &dwOldProtect);
    return dwOldProtect;
    }[/code]

    Going to eventually apply what I've learned to all of my code. After seeing the changes and largely increased understandability in such a small piece of code, I think every programmer should live by this book.


    DOWNLOAD
    http://www.mediafire.com/?ney1ywi2yzz

  2. #2

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Books like this one every programmer should read...

    Thanks for sharing this!

  3. #3
    Senior Member
    Join Date
    Mar 2007
    Posts
    766

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    [code=cpp]void* memoryHelper::getData(DWORD address, DWORD size)
    [/code]

    This function takes in a size variable, yet it isn't used anywhere in the function. A possible mistake? Also why are you allocating a copy when returning data, why not just return as a const pointer and save your self some clock cycles?

  4. #4

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Quote Originally Posted by jeremic
    [code=cpp]void* memoryHelper::getData(DWORD address, DWORD size)
    [/code]

    This function takes in a size variable, yet it isn't used anywhere in the function. A possible mistake? Also why are you allocating a copy when returning data, why not just return as a const pointer and save your self some clock cycles?
    1. I've optimized that class like 3 times since this post, ahah. That was the initial one.
    2. I'm not paying much attention to detail as I am just cleaning house to put some of this stuff to use.
    3. The size thing was a mistake, I caught it a while after posting. It should be where the 4 is.

    EDIT
    I also love how Jeremic finds it cute to correct me and pay no attention whatsoever to the main point of the thread. <3

  5. #5
    Senior Member
    Join Date
    Sep 2007
    Posts
    230

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Downloaded the book the other day when I seen you post it in the Shoutbox. I have only taken a fairly quick look at the first five chapters so far and can't say I agree with absolutely everything he said, mainly concerning functions (that isn't to say I haven't taken a few things away to improve my coding of functions though).

    I do agree that it is a good and interesting book though and every serious programmer should take a look at it, thanks for posting it Dark.

  6. #6

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    I can't read this book, too much Java makes my eyes hurt :-( I'll have to go outside for a while.

    Although the author has many good points, I really disagree with some of his proposals (in particular, concerning functions, and also some about comments). He advocates writing functions so that they do one thing really well, but then he tends to factor the logic out into separate three line functions and you are left with a mess of a thousand funcs that you don't know where to start reading and how they interrelate with one another, wtf? Can you really expect a three line function in Java (or most other languages) to do something meaningful?

    Chapter about unit tests would be interesting, I never managed to grasp the concept properly, but it's too short (for example how do you test a method that depends on a ton of complex state) to be useful. Also I'm disappointed by the chapter on concurrency (very little mention at all of no-shared-mutable-state Erlang-like model).

    OTOH, the chapter on smells and heuristics looks like a fun read, derived from practice :-)

    Quote Originally Posted by DarkstaR
    If you're going to skim this book, don't bother. You'll only disagree with half of what you read and misunderstand everything else.
    Looks like you are right :-p

  7. #7

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Yeah, when skimming I disagreed with alot but after reading full chapters and looking at code examples I realized the logic in his ideas. OFC, I don't agree about all functions being short.. Somewhere must be some functions that tie everything together, right? I'm pretty sure hes going to discuss that in the chapter about "Systems," which I'll be reading today.

  8. #8

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Very good book,i will try reading it in next days(i dont like do read in English).

    I'm the only one who's feel fun in this:



  9. #9

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    Its made me laugh a few times, haha. Sometimes its just funny and other times its like LOL I TOTALLY DO THAT TOO

  10. #10
    Junior Member
    Join Date
    Aug 2010
    Posts
    5

    RE: [Book] Clean Code: A Handbook of Agile Software Craftsmanship

    You're welcome everyone, I'm that "friend" (I prefer butt buddy).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •