wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int[] arr = new int[96]; arr[96] = 5;
int[] arr = new int[96]; if (96 < arr.length) arr[96] = 5;
Check bounds.
Java
while num > 7 num -= 1
while num > 7: num -= 1
Colon missing after while.
Python
if (num = 27) {{}}
if (num == 27) {{}}
Use ==.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
disp('output')
disp('output')
Correct.
MATLAB
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
let mut val=83; let ref1=&mut val; let ref2=&mut val;
let mut val=83; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
if result > 95 puts 'output'
if result > 95 puts 'output' end
Add 'end'.
Ruby
let result = 80; let result = 69;
let result = 80; result = 69;
Duplicate declaration.
JavaScript
val val: Int = 'info'
val val: String = 'info'
Fix type.
Kotlin
item == '45'
item === 45
Use strict equality.
JavaScript
if val = 78 {{}}
if val == 78 {{}}
Use ==.
Swift
'36' + 80
36 + 80
Avoid string coercion.
JavaScript
let text = String::from("test"); let r=&text; text.push_str("!");
let mut text = String::from("test"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
list[52]
if (length(list) >= 52) list[52]
Check length.
R
list[52]
if list.indices.contains(52) {{ list[52] }}
Check index.
Swift
DELETE FROM items WHERE name=48
DELETE FROM items WHERE name=48;
Add semicolon.
SQL
UPDATE products SET name='test' WHERE status=43
UPDATE products SET name='test' WHERE status=43;
Add semicolon.
SQL
[x*x for x in items if x > 41]
[x*x for x in items if x > 41]
Correct list comprehension.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const foo;
const foo = 32;
Initialize const.
JavaScript
print 'test'
print 'test';
Add semicolon.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if data = 4
if data == 4
Use ==.
Go
if (data = 7) {{}}
if (data == 7) {{}}
Use ==.
Kotlin
const z = 3; z = 79;
let z = 3; z = 79;
Cannot reassign const.
JavaScript
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
["output", 68]
["output", 68]
Correct.
JSON
my @arr = (49,88,77);
my @arr = (49,88,77);
Correct.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<note><age>data</age><age>66</age></note
<note><age>data</age><age>66</age></note>
Add closing >.
XML
println('info')
println("info")
Double quotes.
Scala
$item = 10; if ($item = 10) {{}}
$item = 10; if ($item == 10) {{}}
Use ==.
PHP
var x int
var x int
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
'info' + 35
'info' + 35.to_s
Convert int.
Ruby
JOIN profiles ON users.id = profiles.id
JOIN profiles ON users.id = profiles.id
Correct.
SQL
function test(): void {{ return 30; }}
function test(): number {{ return 30; }}
Return type mismatch.
TypeScript
yield y
yield y
Correct yield.
Python
if ($result = 45) {{}}
if ($result -eq 45) {{}}
Use -eq.
PowerShell
for (data in data)
for (data of data)
for...in iterates keys.
JavaScript
x := 48
x := 48
Correct.
Go
assert num > 1
assert num > 1
Correct.
Python
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
var x = 85;
var x = 85;
Correct.
Dart
function render() {{ echo 'value'; }}
function render() {{ echo 'value'; }}
Correct.
PHP
result = 28
result=28
No spaces.
Shell
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(8);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(8);
Correct.
Node.js
val data = 'info'
val data = "info"
Double quotes.
Kotlin
const index;
const index = 60;
Initialize const.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE items SET age='data' WHERE role=97
UPDATE items SET age='data' WHERE role=97;
Add semicolon.
SQL
if ($result = 44)
if ($result == 44)
Use ==.
Perl
DELETE FROM users WHERE id=23
DELETE FROM users WHERE id=23;
Add semicolon.
SQL
<note name='message'/>
<note name="message"/>
Double quotes.
XML
<hr></hr>
<hr>
Self-closing.
HTML
["world", 91]
["world", 91]
Correct.
JSON
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if x = 21 then print('data') end
if x == 21 then print('data') end
Use ==.
Lua
name: result id: test,
name: result id: test
Remove comma.
YAML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
String name = 'message';
String name = 'message';
Correct.
Dart
yield val
yield val
Correct yield.
Python
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
{{'name':'info'}}
{{"name":"info"}}
Use double quotes.
JSON
if (y = 69) {{}}
if (y == 69) {{}}
Use ==.
Kotlin
let mut temp=24; let ref1=&mut temp; let r2=&mut temp;
let mut temp=24; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
WHERE name = '73'
WHERE name = 73
Don't quote integer.
SQL
val y: Int = 'world'
val y: String = 'world'
Fix type.
Kotlin
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (count = 86) {}
if (count == 86) {}
Use ==.
Dart
if (c = 44)
if (c == 44)
Use ==.
C++
while num > 65 num -= 1
while num > 65: num -= 1
Colon missing after while.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let result = 46;
let result = 46;
Correct.
JavaScript
let str1 = String::from("value"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
disp('info')
disp('info')
Correct.
MATLAB
function foo(item:string){{return item;}} foo(25);
function foo(item:string){{return item;}} foo('test');
Pass correct type.
TypeScript
SELECT * FROM products WHRE age=10;
SELECT * FROM products WHERE age=10;
Fix WHERE.
SQL
var x int
var x int
Correct.
Go
<br></br>
<br>
Self-closing.
HTML
class Product {{ int index; }};
class Product {{ public: int index; }};
Make public.
C++