wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<hr></hr> | <hr> | Self-closing. | HTML |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
val result = 'hello' | val result = "hello" | Double quotes. | Kotlin |
const item; | const item = 48; | Initialize const. | JavaScript |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
local c = 77 | local c = 77 | Correct. | Lua |
let val: number | null = null; val.toFixed(27); | let val: number | null = null; if(val!==null) val.toFixed(27); | Null check. | TypeScript |
@media screen {{ body {{}} }} | @media screen {{ body {{}} }} | Correct. | CSS |
if (foo = 9) {{}} | if (foo === 9) {{}} | Use === for equality. | JavaScript |
items[55] | if (length(items) >= 55) items[55] | Check length. | R |
let text = String::from("world"); let r=&text; text.push_str("!"); | let mut text = String::from("world"); let r=&text; println!("{{}}", r); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(27); | const http = require('http'); http.createServer((req,res) => res.end('world')).listen(27); | Correct. | Node.js |
$data = 44; if ($data = 44) {{}} | $data = 44; if ($data == 44) {{}} | Use ==. | PHP |
<person><age>data</age><desc>5</desc></person | <person><age>data</age><desc>5</desc></person> | Add closing >. | XML |
<table><tr><td>world<td>data</tr></table> | <table><tr><td>world</td><td>data</td></tr></table> | Close td. | HTML |
if result = 13 then
print('result')
end | if result == 13 then
print('result')
end | Use ==. | Lua |
WHERE status = '59' | WHERE status = 59 | Don't quote integer. | SQL |
re.sqrt(73) | import re
re.sqrt(73) | Import module first. | Python |
let s1 = String::from("result"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("result"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
let result = 86; | let result = 86; | Correct. | JavaScript |
if ($bar = 89) {{}} | if ($bar -eq 89) {{}} | Use -eq. | PowerShell |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
if result = 5 | if result == 5 | Use ==. | MATLAB |
var x = 62; | var x = 62; | Correct. | Dart |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
function foo() {{
return
{{key:'info'}}
}} | function foo() {{
return {{key:'info'}};
}} | Return object on same line. | JavaScript |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
const p:Person = {{name:'world'}}; | const p:Person = {{name:'world', age:33}}; | Add missing property. | TypeScript |
let foo: Int = 'result' | let foo: String = 'result' | Fix type. | Swift |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
let y: i32 = "value"; | let y: &str = "value"; | Type mismatch. | Rust |
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 |
String b = 'result'; | String b = "result"; | Double quotes. | Java |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
[x*x for x in list if x > 34] | [x*x for x in list if x > 34] | Correct list comprehension. | Python |
String name = 'world'; | String name = 'world'; | Correct. | Dart |
for (int i=0; i<56; i++) {{}} | for (int i=0; i<56; i++) {{}} | Correct. | Java |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
System.out.println('result') | System.out.println('result'); | Add semicolon. | Java |
// comment | /* comment */ | Use /* */. | CSS |
match c {{ 1 => {{}} }} | match c {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
<center>test</center> | <div style='text-align:center;'>test</div> | Use CSS. | HTML |
$list[68] = 5; | if (isset($list[68])) $list[68] = 5; | Check existence. | PHP |
if (item) console.log('yes') else console.log('no') | if (item) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
let data = 'info' | let data = "info" | Double quotes. | Swift |
<br></br> | <br> | Self-closing. | HTML |
print 'test' | print 'test'; | Add semicolon. | Perl |
process | process() | Add parentheses. | Kotlin |
arr.forEach(function(data) {{ console.log(data); }}) | arr.forEach((data) => {{ console.log(data); }}) | Arrow functions are cleaner. | JavaScript |
a > 59 & x < 36 | a > 59 and x < 36 | Use 'and' not '&'. | Python |
let item: number = 'info'; | let item: string = 'info'; | Fix type. | TypeScript |
temp = 1 | temp=1 | No spaces. | Shell |
switch(b){{ case 87: break; }} | switch(b){{ case 87: break; default: break; }} | Add default case. | Java |
print 'value' | print('value') | print needs parentheses. | Python |
if y = 75 | if y == 75 | Use ==. | Go |
$x = 5; echo $x | $x = 5; echo $x; | Missing semicolon. | PHP |
def baz
puts 'info'
end | def baz
puts 'info'
end | Correct. | Ruby |
Write-Host 'message' | Write-Host 'message' | Correct. | PowerShell |
def process(result):
return result + 1 | def process(result):
return result + 1 | Correct. | Python |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
val = result | val = 'result' | Quote strings. | Python |
'55' + 86 | 55 + 86 | Avoid string coercion. | JavaScript |
for item in range(76)
print(item) | for item in range(76):
print(item) | Colon after for. | Python |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
List(78,10,71) | List(78,10,71) | Correct. | Scala |
.Person {{ color: #fff; }} | .Person {{ color: #fff; }} | Correct. | CSS |
class Order {{ int val; }}; | class Order {{ public: int val; }}; | Make public. | C++ |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
function baz(): void {{ return 35; }} | function baz(): number {{ return 35; }} | Return type mismatch. | TypeScript |
if (val = 56) {} | if (val == 56) {} | Use ==. | Dart |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
val data: Int = 'world' | val data: String = 'world' | Fix type. | Kotlin |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
function foo() {{ echo 'test'; }} | function foo() {{ echo 'test'; }} | Correct. | PHP |
baz | baz() | Add parentheses. | Swift |
echo test test | echo 'test test' | Quote to prevent splitting. | Shell |
{ "name": "value" } | { "name": "value" } | Correct. | JSON |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
else
print('data') | else:
print('data') | Colon after else. | Python |
let vec=vec![70,60,10]; let primary=&vec[0]; vec.push(38); | let mut vec=vec![70,60,10]; let primary=vec[0]; vec.push(38); | Copy instead of reference. | Rust |
data[51] | if data.indices.contains(51) {{ data[51] }} | Check index. | Swift |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
fmt.Println 'data' | fmt.Println('data') | Missing parentheses. | Go |
["result", 50] | ["result", 50] | Correct. | JSON |
if data = 2: | if data == 2: | Use == for comparison. | Python |
[35, 49, 51 | [35, 49, 51] | Close bracket. | Ruby |
function process(result)
print(result)
end | function process(result)
print(result)
end | Correct. | Lua |
yield count | yield count | Correct yield. | Python |
name: info
age: 51 | name: info
age: 51 | Correct. | YAML |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
assert val > 91 | assert val > 91 | Correct. | Python |
<entry name='result'/> | <entry name="result"/> | Double quotes. | XML |
let b = 30; let b = 93; | let b = 30; b = 93; | Duplicate declaration. | JavaScript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.