DEV Community

Cover image for What's Your Coding Quirk?
Ben Halpern for CodeNewbie

Posted on

What's Your Coding Quirk?

If the debuggers captured a candid shot of you coding, what quirky behavior, habit, or unusual thing would they discover?

Follow the CodeNewbie Org and #codenewbie for more discussions and online camaraderie!

Top comments (13)

Collapse
 
schemetastic profile image
Schemetastic (Rodrigo)

In JS, to add +1 value I don't usually use the ++ operand, instead I use += 1...

let conter = 0;

// Drake meme: rejecting
counter ++;

// Drake meme: approving
counter += 1;
Enter fullscreen mode Exit fullscreen mode

It just feels more semantic to me, haha.

Collapse
 
sjmulder profile image
Sijmen J. Mulder

I'd be fine with both of those but I also relish in exploiting post-increment. *dst++ = *src++ yesss

Collapse
 
schemetastic profile image
Schemetastic (Rodrigo)

What it does??

Thread Thread
 
sjmulder profile image
Sijmen J. Mulder • Edited

It's a string-copying idom in C. Full context:

/* copy string into buffer */
void strcpy(char *dst, char *src) {
        while (*src)
                *dst++ = *src++;
}
Enter fullscreen mode Exit fullscreen mode

It's equivalent to:

void strcpy(char *dst, char *src) {
        while (*src) {       /* while src isn't pointing to nul character (terminator) */
                *dst = *src; /* copy the char at 'src' to char at 'dst' (both pointers) */ 
                src += 1;    /* increment src pointer to next char */
                dst += 1;    /* increment dst pointer to next char */
        }
}
Enter fullscreen mode Exit fullscreen mode

It's really not something to make a habit of but in this specific context, C string copying, it's a common idiom.

See also sjmulder.nl/2023/casey-interview-2...

Thread Thread
 
schemetastic profile image
Schemetastic (Rodrigo)

Haha, I don't think I'll be learning C in this life, but I'm surprised by people who have the strength to learn it. Kudos.

Thread Thread
 
sjmulder profile image
Sijmen J. Mulder

Fair enough! I learnt it years ago downporting a little C++ game for practice and finding that it forced me to write simpler and more to-the-point code. Essentially: data-oriented programming. Those concepts are useful in other languages too!

Thread Thread
 
schemetastic profile image
Schemetastic (Rodrigo)

Great! If you know C I would bet that you know a few other languages.

Collapse
 
mistval profile image
Randall

Speaking of debuggers, I like typing debugger; statements into JS/TS code while debugging. They cause the debugger to break much more reliably (sometimes an issue with TS), are easy to find, and they move with the code as I make changes. I can't remember ever seeing anyone else type enter a debugger; statement into their code.

Collapse
 
sjmulder profile image
Sijmen J. Mulder

Oh yes that's very useful! I do it sometimes. Usually it's easier to just click the line in the debugger but with JavaScript it can be a chore to find it in the inspector. Then adding a 'debugger;' line can be helpful.

Collapse
 
svemaraju profile image
Srikanth
  • In early days of coding used to put lots of print statements like print(100, value) .... print(200, value) instead of using the debugger.
  • I like pretty printing JSON in terminal.
  • If I have 10 files to commit, I will do git diff on each file and observe the changes before committing.
Collapse
 
sjmulder profile image
Sijmen J. Mulder

I feel like print statements are great for debugging, they're good at showing the order of things or changes over time.

For git, try git add -p. Lets you review and stage one change at a time. Or just git diff (for unstaged changes) or git diff --cached (for staged changes), then you don't need to run 10 diff commands in sequence.

Collapse
 
nikunjbhatt profile image
Nikunj Bhatt

I use <big> and <b> tags in HTML to highlight a paragraph between other paragraphs:

<p>This is a simple paragraph.</p>
<p><big><b>This is a highlighted paragraph.</b></big></p>
Enter fullscreen mode Exit fullscreen mode

India's Hindi Film Industry's one of the legendary actors Amitabh Bachchan is also known as "Big B". (However, I am not a fan of him, I just use these tags when defining a class in a CSS file is "costlier". (When such text is written only one or two times.) (I know that <big> tag is deprecated. But it is still working in web browsers, and it is never going away (from how much I know HTML and the web browsers 😄). And even if it is removed, it isn't significant and it will not produce any error, it will simply be ignored by the browsers.)

Collapse
 
sjmulder profile image
Sijmen J. Mulder

When writing C, I declare my variables at the start of the function like it's 1989. I just like that separation between storage and logic.