OtterZ's blog

By OtterZ, history, 8 months ago, In English

In fact,I don't want to use this to detect LLMs,but it's very important to say that because something wrong might happen if you don't do that.

In fact when I trying to find a mistake in a code,I saw:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x)
		if(p[i - 1].x != 0)
			f2 ++;
	else{
                dt2 ++;
		if(!gt[dt2 + cnt1])
			f2 ++;
	}
}

And found the code with same result is this:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x){
		if(p[i - 1].x != 0)
			f2 ++;
	        else{
                        dt2 ++;
		        if(!gt[dt2 + cnt1])
			        f2 ++;
	        }
        }
}

This will lead to WA and make you cost a long time to find mistake.So please write like this:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x){
		if(p[i - 1].x != 0){
			f2 ++;
                }
        }
	else{
                dt2 ++;
		if(!gt[dt2 + cnt1]){
			f2 ++;
                }
	}
}

To make sure the structure is right.

  • Vote: I like it
  • +50
  • Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it +35 Vote: I do not like it

I recommend using -Wall -Wextra, it catches this structure when you have if if else without curly brackets. It's actually quite useful in general, because in CP you can just ignore the stupid warnings about signedness and such, and it catches silly mistakes like this for you.

»
8 months ago, hide # |
 
Vote: I like it +36 Vote: I do not like it

I don't think any LLM writes a code without strict {}s.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    what about simple ifs
    like if(flag) return;
    I believe some llm can do it?

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      if into if make this a problem,sometimes we found we have to add things in ifs,so its better add it.

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I was talking about the llm behavior.

        but, I agree that every if() should be followed by {}, with the exception of very small project/cp codes, that will be forgotten after few days.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Some would go CP mode when the problem is hard, and begin #define rep(i, n) for (int i = 0; i < (n); i++)

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

CPers, and their disdain for code formatters.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I learnt this the hard way. Ever since, I've been using braces for each structure I open.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

So I am an LLM! I usually write code without the curly brackets after the if statement, but I was aware of this error beforehand, and I have always managed to work around it. Anyway, thanks for the note brother

Not important
»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Ig its pretty common, the else is matched with the nearest if in the same scope or block. Few textbooks call this dangling else.