Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Fun activity What was your biggest coding "Aha!" moment?

kolakube

Active Coder
Like a lot of others here, coding has been a part of my life for a long time. Like any other skill one masters, a deep connection is developed within your mind and body to the craft.

I don't know how crazy this sounds but there are certain file names, functions, and other blocks of code that I can look at that I wrote years ago and suddenly be transported back in time to the moment I wrote them.

Suddenly I can remember where I was, a smell around me, and even the people who were present in my life both in that moment or just in general. Coding really has become a spiritual experience for me and I will fight tooth and nail against anybody who doesn't see the art in what we do.

The kind of connections I am describing here are ingrained into our brains through a series of "Aha!" moments; the kinds of lessons that we learn once and will know forever because of how monumental of a discovery they were to future creations.

In this thread let's share our biggest moments of clarity and concepts learned that have been invaluable to our work. There are three concepts I always come back to that completely changed the way I write code:
  1. Passing data through functions
    This one took me longer to understand than I'd care to admit, but learning how to pass data through functions quickly reoriented my mind to write more repeatable and organized code. At the most basic level in PHP, this concept looks like this:
    PHP:
    function my_name( $name ) {
        return 'My name is ' . $name;
    }
    
    echo my_name( 'Alex' );

  2. Foreach and building data arrays
    The key concept here is to learn how to think in terms of data and not just single elements. Building and traversing through arrays of data allows you to accomplish far more by writing less code and can make your code far easier to plug into. For example, do you think it's easier for a client to edit a list of text elements by scrolling through an HTML document, or would a single file with an array list be easier for them to plug into? Furthermore, if you can isolate values into a simple array list, what else can you do with it? The possibilities are endless when you think in the mindset of data.
    PHP:
    <?php
    $data = array(
        'section_1' => array(
            'title' => 'My first headline',
            'text' => 'Some description text',
            'url' => 'https://domain.com'
        ),
        'section_2' => array(
            'title' => 'Another headline',
            'text' => 'Even more description text',
            'url' => 'https://another-domain.com'
        )
    );
    
    foreach ( $data as $section_id => $fields ) : ?>
        <div id="<?php echo $section_id; ?>">
            <h2><?php echo $fields['title']; ?></h2>
            <p><?php echo $fields['text']; ?></p>
            <p><a href="<?php echo $fields['url']; ?>">Visit website</a></p>
        </div>
    <?php endforeach; ?>

  3. Class extension and OOP
    Maybe a more common one, but I was skeptical about how useful writing classes were. Sure, I could come up with much simpler method (function) names now that I have a unique Class wrapper, but just that alone didn't seem worth all of the extra indents and more long-winded ways to access those methods outside of the class. But then I learned how to extend classes and use an entirely premade class environment in a brand new class without writing any extra code.
    PHP:
    // Create a main class with master methods
    class MainClass {
        public function name( $name ) {
            return 'My name is ' . $name;
        }
    }
    
    // Create a subclass that uses the name() method from MainClass
    
    class SubClass extends MainClass {
        public function someMethod() {
            return $this->name( 'Alex' );
        }
    }
I hope this post has inspired you to think back to your own "Aha!" moments and share them with the community. Coding examples are preferred, but we would just love to hear the concepts that mean the most to your own style.
 
When I have made my first travel base website in 2015 after completing my training in ASP.Net that moment and feeling is just another level, and can't compare that to anything else.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom