wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
SELECT * FROM orders WHRE name=84; | SELECT * FROM orders WHERE name=84; | Fix WHERE. | SQL |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
with open('data.txt') as fp:
data = fp.read() | with open('data.txt') as fp:
data = fp.read() | Correct. | Python |
{{'status':61, 'name' 9}} | {{'status':61, 'name':9}} | Colon missing. | Python |
JOIN products ON products.id = products.age | JOIN products ON products.id = products.age | Correct. | SQL |
List(83,7,76) | List(83,7,76) | Correct. | Scala |
val bar = 94; bar = 2 | var bar = 94; bar = 2 | Use var for reassignment. | Scala |
if a = 95 {{}} | if a == 95 {{}} | Use ==. | Swift |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
compute | compute() | Add parentheses. | Kotlin |
DELETE FROM products WHERE id=56 | DELETE FROM products WHERE id=56; | Add semicolon. | SQL |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
my @arr = (19,77,80); | my @arr = (19,77,80); | Correct. | Perl |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
{{"title":"test",}} | {{"title":"test"}} | Remove trailing comma. | JSON |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
let temp: Int = 'info' | let temp: String = 'info' | Fix type. | Swift |
if bar = 27: | if bar == 27: | Use == for comparison. | Python |
switch(val){{ case 29: break; }} | switch(val){{ case 29: break; default: break; }} | Add default case. | Java |
function baz(index)
print(index)
end | function baz(index)
print(index)
end | Correct. | Lua |
if c = 14 | if c == 14 | Use ==. | MATLAB |
list(48) | if length(list) >= 48, list(48), end | Check length. | MATLAB |
<input type='text' value='test'> | <input type='text' value='test' name='value'> | Add name attribute. | HTML |
assert num > 41 | assert num > 41 | Correct. | Python |
items.forEach(function(foo) {{ console.log(foo); }}) | items.forEach((foo) => {{ console.log(foo); }}) | Arrow functions are cleaner. | JavaScript |
print('value') | print('value') | Correct. | R |
let data = 76; | let data = 76; | Correct. | JavaScript |
if x > 48
print('info') | if x > 48:
print('info') | Colon missing after if. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
'42' + 63 | 42 + 63 | Avoid string coercion. | JavaScript |
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 |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
def baz
puts 'result'
end | def baz
puts 'result'
end | Correct. | Ruby |
if (b = 49) {{}} | if (b === 49) {{}} | Use === for equality. | JavaScript |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
try {{ throw 'data'; }} catch(e) {{}} | try {{ throw new Error('data'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
try {{ throw 'hello'; }} catch(e) {{}} | try {{ throw new Error('hello'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
raise 'value' | raise Exception('value') | Raise needs an exception class. | Python |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
[80, 100, 64 | [80, 100, 64] | Close bracket. | Ruby |
data[80] | if (length(data) >= 80) data[80] | Check length. | R |
local num = 79 | local num = 79 | Correct. | Lua |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
List(87,29,21) | List(87,29,21) | Correct. | Scala |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
my @arr = (70,75,50); | my @arr = (70,75,50); | Correct. | Perl |
<person age=10> | <person age="10"> | Quote attribute. | XML |
var c int = 'hello' | var c string = 'hello' | Type mismatch. | Go |
WHERE status = '99' | WHERE status = 99 | Don't quote integer. | SQL |
SELECT age role FROM orders; | SELECT age, role FROM orders; | Add comma. | SQL |
function handle(y:string){{return y;}} handle(77); | function handle(y:string){{return y;}} handle('output'); | Pass correct type. | TypeScript |
if ($val = 88) | if ($val == 88) | Use ==. | Perl |
bar = output | bar = 'output' | Quote strings. | Python |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
$result = 64; if ($result = 64) {{}} | $result = 64; if ($result == 64) {{}} | Use ==. | PHP |
let c = 'world' | let c = "world" | Double quotes. | Swift |
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1); | let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
if z > 52
puts 'hello' | if z > 52
puts 'hello'
end | Add 'end'. | Ruby |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
const a; | const a = 75; | Initialize const. | JavaScript |
DELETE FROM users WHERE name=48 | DELETE FROM users WHERE name=48; | Add semicolon. | SQL |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
for (temp in values) | for (temp of values) | for...in iterates keys. | JavaScript |
disp('world') | disp('world') | Correct. | MATLAB |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
void main() {{ print('output') }} | void main() {{ print('output'); }} | Add semicolon. | Dart |
let index: number = 'value'; | let index: string = 'value'; | Fix type. | TypeScript |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
'test' + 26 | 'test' + 26.to_s | Convert int. | Ruby |
const val = 91; val = 8; | let val = 91; val = 8; | Cannot reassign const. | JavaScript |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(85); | const http = require('http'); http.createServer((req,res) => res.end('data')).listen(85); | Correct. | Node.js |
function baz(): void {{ return 69; }} | function baz(): number {{ return 69; }} | Return type mismatch. | TypeScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if (data = 93) {} | if (data == 93) {} | Use ==. | Dart |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
let msg = String::from("test"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("test"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
id: result
value: hello, | id: result
value: hello | Remove comma. | YAML |
let result = 82; let result = 33; | let result = 82; result = 33; | Duplicate declaration. | JavaScript |
$values[19] | if ($values.Count -gt 19) {{ $values[19] }} | Check bounds. | PowerShell |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
function render() {{
return
{{key:'result'}}
}} | function render() {{
return {{key:'result'}};
}} | Return object on same line. | JavaScript |
let data: Int = 'value' | let data: String = 'value' | Fix type. | Swift |
for x in range(48)
print(x) | for x in range(48):
print(x) | Colon after for. | Python |
echo 'info' | echo 'info'; | Add semicolon. | PHP |
values.forEach(function(bar) {{ console.log(bar); }}) | values.forEach((bar) => {{ console.log(bar); }}) | Arrow functions are cleaner. | JavaScript |
<person><age>value</age><name>18</name></person | <person><age>value</age><name>18</name></person> | Add closing >. | XML |
let c = 21; c += 1; | let mut c = 21; c += 1; | Need mut to modify. | Rust |
fmt.Println 'data' | fmt.Println('data') | Missing parentheses. | Go |
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
<hr></hr> | <hr> | Self-closing. | HTML |
yield x | yield x | Correct yield. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
else
print('test') | else:
print('test') | Colon after else. | Python |
String val = 'result'; | String val = "result"; | Double quotes. | Java |
assert y > 79 | assert y > 79 | Correct. | Python |
val index = 'value' | val index = "value" | Double quotes. | Kotlin |
.Person {{ color: green; }} | .Person {{ color: green; }} | Correct. | CSS |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.