• Log in or sign up for an account here: https://www.sythe.org/login

Am I developing any bad habits?

Arya

Guru

$25 USD Donor New
Joined
Jul 20, 2008
Sythe Gold
160
Messages
1,414
Age
34
Location
US
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]
 
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
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 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
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.
 
Gohan has AIDS
Sythe's 10th Anniversary
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;
}
 
Runescape Gamblingrunescape gambling
Back
Top