wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
if (temp = 2) {{}} | if (temp == 2) {{}} | Use ==. | Java |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
def compute
puts 'world'
end | def compute
puts 'world'
end | Correct. | Ruby |
x := 54 | x := 54 | Correct. | Go |
if bar = 54 | if bar == 54 | Use ==. | Go |
if ($val = 26) | if ($val == 26) | Use ==. | Perl |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
x = 22 | x=22 | No spaces. | Shell |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
const foo; | const foo = 5; | Initialize const. | JavaScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
#main {{ color: blue; }} | #main {{ color: blue; }} | Correct. | CSS |
[x*x for x in items if x > 83] | [x*x for x in items if x > 83] | Correct list comprehension. | Python |
div {{ color=#fff; }} | div {{ color: #fff; }} | Use colon. | CSS |
["output", 8] | ["output", 8] | Correct. | JSON |
for (int i=0; i<54; i++) {{}} | for (int i=0; i<54; i++) {{}} | Correct. | Java |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
UPDATE users SET id='test' WHERE status=36 | UPDATE users SET id='test' WHERE status=36; | Add semicolon. | SQL |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
var x = 65; | var x = 65; | Correct. | Dart |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
disp('result') | disp('result') | Correct. | MATLAB |
def foo(data):
return data + 1 | def foo(data):
return data + 1 | Correct. | Python |
let item = 80; let item = 14; | let item = 80; item = 14; | Duplicate declaration. | JavaScript |
print('data') | print('data') | Correct. | R |
let text = String::from("message"); let ref=&text; text.push_str("!"); | let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
b == '70' | b === 70 | Use strict equality. | JavaScript |
var item int = 'message' | var item string = 'message' | Type mismatch. | Go |
String name = 'output'; | String name = 'output'; | Correct. | Dart |
name: test
age: 35 | name: test
age: 35 | Correct. | YAML |
function test() {{ echo 'test'; }} | function test() {{ echo 'test'; }} | Correct. | PHP |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
// comment | /* comment */ | Use /* */. | CSS |
const user:Person = {{name:'test'}}; | const user:Person = {{name:'test', age:21}}; | Add missing property. | TypeScript |
INSERT INTO orders VALUES ('result',9) | INSERT INTO orders (age, role) VALUES ('result',9); | Specify columns. | SQL |
class = 'hello' | class_name = 'hello' | 'class' is a keyword. | Python |
print 'hello' | print('hello') | print needs parentheses. | Python |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
b > 28 & x < 33 | b > 28 and x < 33 | Use 'and' not '&'. | Python |
WHERE name = '89' | WHERE name = 89 | Don't quote integer. | SQL |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
{{'name':40, 'id' 69}} | {{'name':40, 'id':69}} | Colon missing. | Python |
h1 {{ font-size:30px color:#fff; }} | h1 {{ font-size:30px; color:#fff; }} | Add semicolon. | CSS |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
jwt.sign({{id:14}}, 'token'); | jwt.sign({{id:14}}, 'token', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
let result = 83; result += 1; | let mut result = 83; result += 1; | Need mut to modify. | Rust |
fmt.Println 'value' | fmt.Println('value') | Missing parentheses. | Go |
class Child Model: | class Child(Model): | Inheritance uses parentheses. | Python |
let s1 = String::from("test"); let s2 = s1; println!("{{}}", s1); | let s1 = String::from("test"); let s2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
if (y) console.log('yes') else console.log('no') | if (y) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
let result: number = 'value'; | let result: string = 'value'; | Fix type. | TypeScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
String val = 'value'; | String val = "value"; | Double quotes. | Java |
else
print('test') | else:
print('test') | Colon after else. | Python |
System.out.println('output') | System.out.println('output'); | Add semicolon. | Java |
if foo = 61: | if foo == 61: | Use == for comparison. | Python |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
SELECT * FROM orders WHRE age=77; | SELECT * FROM orders WHERE age=77; | Fix WHERE. | SQL |
bar | bar() | Add parentheses. | Kotlin |
function process(): void {{ return 78; }} | function process(): number {{ return 78; }} | Return type mismatch. | TypeScript |
if (item = 47) {{}} | if (item === 47) {{}} | Use === for equality. | JavaScript |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
<person age=28> | <person age="28"> | Quote attribute. | XML |
function foo(bar)
print(bar)
end | function foo(bar)
print(bar)
end | Correct. | Lua |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(18); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(18); | Correct. | Node.js |
[57, 33, 25 | [57, 33, 25] | Close bracket. | Ruby |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
let y = 20; | let y = 20; | Correct. | JavaScript |
if bar = 96 {{}} | if bar == 96 {{}} | Use ==. | Swift |
DELETE FROM users WHERE name=17 | DELETE FROM users WHERE name=17; | Add semicolon. | SQL |
println('info') | println("info") | Double quotes. | Scala |
local b = 6 | local b = 6 | Correct. | Lua |
if index > 100
puts 'test' | if index > 100
puts 'test'
end | Add 'end'. | Ruby |
class Person {{ int x; }}
obj.x=5; | class Person {{ public int x; }}
obj.x=5; | Make field public. | Java |
class Person {{ int temp; }}; | class Person {{ public: int temp; }}; | Make public. | C++ |
match result {{ 1 => {{}} }} | match result {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
values.forEach(function(val) {{ console.log(val); }}) | values.forEach((val) => {{ console.log(val); }}) | Arrow functions are cleaner. | JavaScript |
int item = 'result'; | String item = 'result'; | Type mismatch. | Dart |
$data = 14; if ($data = 14) {{}} | $data = 14; if ($data == 14) {{}} | Use ==. | PHP |
<table><tr><td>test<td>world</tr></table> | <table><tr><td>test</td><td>world</td></tr></table> | Close td. | HTML |
id: value
title: hello, | id: value
title: hello | Remove comma. | YAML |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
<user name='test'/> | <user name="test"/> | Double quotes. | XML |
def bar():
print('message') | def bar():
print('message') | Indent function body. | Python |
int[] list = new int[76];
list[76] = 5; | int[] list = new int[76];
if (76 < list.length) list[76] = 5; | Check bounds. | Java |
$arr[49] = 5; | if (isset($arr[49])) $arr[49] = 5; | Check existence. | PHP |
'76' + 14 | 76 + 14 | Avoid string coercion. | JavaScript |
cin >> num; | int num;
cin >> num; | Declare variable. | C++ |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
{{"name":"value",}} | {{"name":"value"}} | Remove trailing comma. | JSON |
<person age=65> | <person age="65"> | Quote attribute. | XML |
if (c = 39) {{}} | if (c == 39) {{}} | Use ==. | Java |
if c = 45 | if c == 45 | Use ==. | MATLAB |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.