Adblock breaks this site

Am I developing any bad habits?

Discussion in 'Programming General' started by Arya, Feb 25, 2015.

  1. Arya

    Arya Guru
    $25 USD Donor New

    Joined:
    Jul 20, 2008
    Posts:
    1,414
    Referrals:
    1
    Sythe Gold:
    160
    Discord Unique ID:
    848009003737153567
    Discord Username:
    aryaauneexus
    Am I developing any bad habits?

    All of this is written from scratch & memory of tutorials. Since I've only been writing collectively for less than 24 hours(give or take), I'm wondering if I'm developing any bad coding habits.

    HTML

    CSS 1

    CSS 2

    End result

    What do y'all think? [imgur pics]
     
  2. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    Am I developing any bad habits?

    Get used to commenting. What you're working on now may not require it, but in the near future when you're working on bigger projects off-and-on you'll be thankful for little labels here and there. Otherwise things look OK. If you're that worried about style check out a style guide or poke around some professional sources to see how they do things.
     
  3. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Am I developing any bad habits?

    Post code as text! Don't worry about bad habits. You grow and evolve as a developer and you will always have bad style and stuff. You can only get it so good. Try your best and just keep improving every day you code.
     
  4. SmokeHut

    SmokeHut Great men grow tired of contentedness.
    $100 USD Donor New

    Joined:
    Aug 17, 2011
    Posts:
    1,504
    Referrals:
    0
    Sythe Gold:
    112
    Discord Unique ID:
    865859811747692554
    Discord Username:
    Okesseril#7961
    Gohan has AIDS Sythe's 10th Anniversary
    Am I developing any bad habits?

    From a brief overview it looks okay. However, as blupig suggested, comments are great for future reference, or when your document begins to get out of hand. I personally fail to comment so much, as I tend to remember why I did that. However, people looking over my code might not have quite as such of a great time.

    The main thing which you need to adhere to is indenting. It's pretty fundamental.

    for instance,

    Code:
    
    <div class="col8-b">
        //content
    </div>
    
    
    In a small div, it's apparent where the div ends, if your div begins to turn into a lot of lines then finding the end of it can be a true nightmare, as well as this, it gives reference to what's included inside of what. So if I want to split a margin somewhere a long the line it's easy to select everything after it, indent it one and add my new div in there.

    I'd fire up my pc and provide a good example, but that is going to require far too much effort..

    So I'll use your code as an example.

    Code:
    <body>
        <div class="heading">
            <div class="jumbotron">
                <h1>Hello</h1>
            </div>
            <p>This is my...</p>
        </div>
    </body>
    
    Also, taking the same approach in CSS helps.

    EDIT: it's also been a while since I've touched css however, if I remember rightly, setting say the paragraph css before changing the class that your setting it to could over-write your paragraph settings as it does it across a broad sense for the class.

    So setting your margin for the paragraph at say 10px; then if you write the class broadly after that to 0px; then you're going to over-write it. So try to use pointers after the initial broad brush over the class.

    I could be wrong, but it just looks odd right now.

    EDIT #2:

    Here's a little more reason to do it.

    This is a fairly non-optimised method for a boolean response that I'm using right now.

    Code:
    -(BOOL) runAgainstLastCard:(NSString *) lastCard withPlayedCard:(NSMutableArray *) playedCard {
        //Convert strings to suits & rank
        
        NSArray *faces = [[NSArray alloc] initWithObjects:@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K", nil];
        NSArray *suits = [[NSArray alloc] initWithObjects:@"h",@"d",@"c",@"s", nil];
        
        int aqua = 0;
        int oneTwoThree = 0;
        
        for (int j = 0; j < [playedCard count]; j++) {
        
            NSString *prevRank;
            NSString *prevSuit;
            NSString *nowRank;
            NSString *nowSuit;
    
            //Ranks up last card, and last suit.
            for (int i = 0; i < [faces count]; i++) {
                if ([lastCard containsString:faces[i]]) {
                    //Match saves suit
                    prevRank = faces[i];
                }
            }
            for (int i = 0; i < [suits count]; i++) {
                if ([lastCard containsString:suits[i]]) {
                    //Match saves suit
                    prevSuit = suits[i];
                }
            }
            //Ranks up new card & suit
            for (int i = 0; i < [faces count]; i++) {
                if ([playedCard[j] containsString:faces[i]]) {
                    //Match saves suit
                    nowRank = faces[i];
                }
            }
            
            for (int i = 0; i < [suits count]; i++) {
                if ([playedCard[j] containsString:suits[i]]) {
                    //Match saves suit
                    nowSuit = suits[i];
                }
            }
            if ([nowRank isEqualToString:@"J"]) {
                return true;
            } else        
            if ([prevRank isEqualToString:nowRank]) {
                lastCard = playedCard[j];
            } else
            if([prevSuit isEqualToString:nowSuit]) {
                if (j == 0) {
                    lastCard = playedCard[j];
                } else {
                    //card needs an int value, if the int value is within -1 or +1 then it's acceptable run, else. Not acceptable return false.
                    int prevRankValue = [self returnRankValue:prevRank];
                    int nowRankValue = [self returnRankValue:nowRank];
                    
                    if (prevRankValue == nowRankValue || prevRankValue == nowRankValue - 1 || prevRankValue == nowRankValue + 1 || (prevRankValue == 12 && nowRankValue == 0) || (prevRankValue == 0 && nowRankValue == 12)) {
                        if (prevRankValue == 12 && nowRankValue == 0) {
                            //Aqua
                            aqua = 1;
                        }
                        if (prevRankValue == 1 && nowRankValue == 0) {
                            oneTwoThree = 1;
                        }
                        if (aqua == 1 && oneTwoThree == 1) {
                            return false;
                        }
                        lastCard = playedCard[j];
                    } else {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }
        
        return true;
    }
    
    Pretty readable, right?

    This is unindented

    Code:
    -(BOOL) runAgainstLastCard:(NSString *) lastCard withPlayedCard:(NSMutableArray *) playedCard {
    //Convert strings to suits & rank
    
    NSArray *faces = [[NSArray alloc] initWithObjects:@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K", nil];
    NSArray *suits = [[NSArray alloc] initWithObjects:@"h",@"d",@"c",@"s", nil];
    
    int aqua = 0;
    int oneTwoThree = 0;
    
    for (int j = 0; j < [playedCard count]; j++) {
    
    NSString *prevRank;
    NSString *prevSuit;
    NSString *nowRank;
    NSString *nowSuit;
    
    //Ranks up last card, and last suit.
    for (int i = 0; i < [faces count]; i++) {
    if ([lastCard containsString:faces[i]]) {
    //Match saves suit
    prevRank = faces[i];
    }
    }
    for (int i = 0; i < [suits count]; i++) {
    if ([lastCard containsString:suits[i]]) {
    //Match saves suit
    prevSuit = suits[i];
    }
    }
    //Ranks up new card & suit
    for (int i = 0; i < [faces count]; i++) {
    if ([playedCard[j] containsString:faces[i]]) {
    //Match saves suit
    nowRank = faces[i];
    }
    }
    
    for (int i = 0; i < [suits count]; i++) {
    if ([playedCard[j] containsString:suits[i]]) {
    //Match saves suit
    nowSuit = suits[i];
    }
    }
    if ([nowRank isEqualToString:@"J"]) {
    return true;
    } else        
    if ([prevRank isEqualToString:nowRank]) {
    lastCard = playedCard[j];
    } else
    if([prevSuit isEqualToString:nowSuit]) {
    if (j == 0) {
    lastCard = playedCard[j];
    } else {
    //card needs an int value, if the int value is within -1 or +1 then it's acceptable run, else. Not acceptable return false.
    int prevRankValue = [self returnRankValue:prevRank];
    int nowRankValue = [self returnRankValue:nowRank];
    
    if (prevRankValue == nowRankValue || prevRankValue == nowRankValue - 1 || prevRankValue == nowRankValue + 1 || (prevRankValue == 12 && nowRankValue == 0) || (prevRankValue == 0 && nowRankValue == 12)) {
    if (prevRankValue == 12 && nowRankValue == 0) {
    //Aqua
    aqua = 1;
    }
    if (prevRankValue == 1 && nowRankValue == 0) {
    oneTwoThree = 1;
    }
    if (aqua == 1 && oneTwoThree == 1) {
    return false;
    }
    lastCard = playedCard[j];
    } else {
    return false;
    }
    }
    } else {
    return false;
    }
    }
    
    return true;
    }
    
    
     
< Anyone have much experience with sockets? | Android Studio Help Required (Paid) >


 
 
Adblock breaks this site