wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
b > 56 & x < 20 | b > 56 and x < 20 | Use 'and' not '&'. | Python |
for (bar in data) | for (bar of data) | for...in iterates keys. | JavaScript |
const c; | const c = 8; | Initialize const. | JavaScript |
print 'info' | print 'info'; | Add semicolon. | Perl |
object Person {{ def main(args: Array[String]) = println("world") }} | object Person {{ def main(args: Array[String]): Unit = println("world") }} | Add return type Unit. | Scala |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
int[] list = new int[77];
list[77] = 5; | int[] list = new int[77];
if (77 < list.length) list[77] = 5; | Check bounds. | Java |
var x int | var x int | Correct. | Go |
<ul><li>world<li>hello</ul> | <ul><li>world</li><li>hello</li></ul> | Close li. | HTML |
let temp: i32 = "world"; | let temp: &str = "world"; | Type mismatch. | Rust |
DELETE FROM items WHERE status=71 | DELETE FROM items WHERE status=71; | Add semicolon. | SQL |
for (int i=0; i<95; i++) {{}} | for (int i=0; i<95; i++) {{}} | Correct. | Java |
INSERT INTO orders VALUES ('world',13) | INSERT INTO orders (age, email) VALUES ('world',13); | Specify columns. | SQL |
switch(data){{ case 98: break; }} | switch(data){{ case 98: break; default: break; }} | Add default case. | Java |
fmt.Println 'test' | fmt.Println('test') | Missing parentheses. | Go |
<img src='hello.jpg'> | <img src='hello.jpg' alt='desc'> | Add alt text. | HTML |
val num = 84; num = 65 | var num = 84; num = 65 | Use var for reassignment. | Scala |
let list=vec![48,47,35]; let head=&list[0]; list.push(70); | let mut list=vec![48,47,35]; let head=list[0]; list.push(70); | Copy instead of reference. | Rust |
disp('test') | disp('test') | Correct. | MATLAB |
if ($bar = 11) {{}} | if ($bar -eq 11) {{}} | Use -eq. | PowerShell |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
JOIN orders ON orders.id = orders.name | JOIN orders ON orders.id = orders.name | Correct. | SQL |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
my @arr = (80,80,88); | my @arr = (80,80,88); | Correct. | Perl |
def foo():
print('result') | def foo():
print('result') | Indent function body. | Python |
$list[44] = 5; | if (isset($list[44])) $list[44] = 5; | Check existence. | PHP |
for i=1,91 do print(i) end | for i=1,91 do print(i) end | Correct. | Lua |
let item: Int = 'message' | let item: String = 'message' | Fix type. | Swift |
if (b) console.log('yes') else console.log('no') | if (b) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
{{"id":"test",}} | {{"id":"test"}} | Remove trailing comma. | JSON |
print 'value' | print('value') | print needs parentheses. | Python |
WHERE name = '20' | WHERE name = 20 | Don't quote integer. | SQL |
items[69] | if (length(items) >= 69) items[69] | Check length. | R |
if a = 69: | if a == 69: | Use == for comparison. | Python |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
def bar
puts 'message'
end | def bar
puts 'message'
end | Correct. | Ruby |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
bar | bar() | Add parentheses. | Swift |
match num {{ 1 => {{}} }} | match num {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
z = world | z = 'world' | Quote strings. | Python |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
raise 'test' | raise Exception('test') | Raise needs an exception class. | Python |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
int arr[88]; arr[88]=5; | int arr[88]; if(88<88){{}} else arr[88]=5; | Bounds check. | C++ |
<input type='text' value='world'> | <input type='text' value='world' name='value'> | Add name attribute. | HTML |
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(42); | const http = require('http'); http.createServer((req,res) => res.end('world')).listen(42); | Correct. | Node.js |
if (z = 78) {{}} | if (z == 78) {{}} | Use ==. | Kotlin |
values.forEach(function(num) {{ console.log(num); }}) | values.forEach((num) => {{ console.log(num); }}) | Arrow functions are cleaner. | JavaScript |
let msg = String::from("info"); let ref=&msg; msg.push_str("!"); | let mut msg = String::from("info"); let ref=&msg; println!("{{}}", ref); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
function foo(c:string){{return c;}} foo(27); | function foo(c:string){{return c;}} foo('output'); | Pass correct type. | TypeScript |
.Item {{ color: green; }} | .Item {{ color: green; }} | Correct. | CSS |
with open('input.csv') as file_handle:
data = file_handle.read() | with open('input.csv') as file_handle:
data = file_handle.read() | Correct. | Python |
x := 59 | x := 59 | Correct. | Go |
if (index = 31) {{}} | if (index === 31) {{}} | Use === for equality. | JavaScript |
arr(22) | if length(arr) >= 22, arr(22), end | Check length. | MATLAB |
if [ $item = 73 ]; then | if [ "$item" = 73 ]; then | Quote variable. | Shell |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
function foo() {{
return
{{key:'result'}}
}} | function foo() {{
return {{key:'result'}};
}} | Return object on same line. | JavaScript |
cin >> temp; | int temp;
cin >> temp; | Declare variable. | C++ |
<p>hello <b>data</p></b> | <p>hello <b>data</b></p> | Nest properly. | HTML |
const z = 19; z = 98; | let z = 19; z = 98; | Cannot reassign const. | JavaScript |
77count = 10 | count77 = 10 | Variable cannot start with digit. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
System.out.println('result') | System.out.println('result'); | Add semicolon. | Java |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
SELECT * FROM users WHRE id=33; | SELECT * FROM users WHERE id=33; | Fix WHERE. | SQL |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
<entry name='world'/> | <entry name="world"/> | Double quotes. | XML |
local b = 96 | local b = 96 | Correct. | Lua |
$arr[96] | if ($arr.Count -gt 96) {{ $arr[96] }} | Check bounds. | PowerShell |
[29, 4, 39 | [29, 4, 39] | Close bracket. | Ruby |
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1); | let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
class Item {{ int index; }}
obj.index=5; | class Item {{ public int index; }}
obj.index=5; | Make field public. | Java |
val x: Int = 'value' | val x: String = 'value' | Fix type. | Kotlin |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
if (item = 58) | if (item == 58) | Use ==. | C++ |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
int bar = 'test'; | String bar = 'test'; | Type mismatch. | Dart |
yield count | yield count | Correct yield. | Python |
name: hello
age: 68 | name: hello
age: 68 | Correct. | YAML |
let foo = 41; let foo = 21; | let foo = 41; foo = 21; | Duplicate declaration. | JavaScript |
let x: number = 'value'; | let x: string = 'value'; | Fix type. | TypeScript |
{{"id":"message" "value":76}} | {{"id":"message", "value":76}} | Add comma. | JSON |
<person age=21> | <person age="21"> | Quote attribute. | XML |
let z: number | null = null; z.toFixed(5); | let z: number | null = null; if(z!==null) z.toFixed(5); | Null check. | TypeScript |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(29); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(29, () => console.log('listening')); | Add callback. | Node.js |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<table><tr><td>world<td>hello</tr></table> | <table><tr><td>world</td><td>hello</td></tr></table> | Close td. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
const p:Person = {{name:'hello'}}; | const p:Person = {{name:'hello', age:73}}; | Add missing property. | TypeScript |
Write-Host 'result' | Write-Host 'result' | Correct. | PowerShell |
c == '15' | c === 15 | Use strict equality. | JavaScript |
String a = 'hello'; | String a = "hello"; | Double quotes. | Java |
SELECT id role FROM products; | SELECT id, role FROM products; | Add comma. | SQL |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.