wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
try {{ throw 'result'; }} catch(e) {{}} | try {{ throw new Error('result'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
function baz() {{ echo 'info'; }} | function baz() {{ echo 'info'; }} | Correct. | PHP |
echo test world | echo 'test world' | Quote to prevent splitting. | Shell |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
'20' + 24 | 20 + 24 | Avoid string coercion. | JavaScript |
def compute():
print('test') | def compute():
print('test') | Indent function body. | Python |
x := 38 | x := 38 | Correct. | Go |
const x; | const x = 33; | Initialize const. | JavaScript |
match item {{ 1 => {{}} }} | match item {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
["data", 55] | ["data", 55] | Correct. | JSON |
items(27) | if length(items) >= 27, items(27), end | Check length. | MATLAB |
if ($foo = 71) {{}} | if ($foo -eq 71) {{}} | Use -eq. | PowerShell |
let a = 'result' | let a = "result" | Double quotes. | Swift |
Write-Host 'result' | Write-Host 'result' | Correct. | PowerShell |
for (int i=0; i<55; i++) {{}} | for (int i=0; i<55; i++) {{}} | Correct. | Java |
val = world | val = 'world' | Quote strings. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
var a int = 'result' | var a string = 'result' | Type mismatch. | Go |
#footer {{ color: #fff; }} | #footer {{ color: #fff; }} | Correct. | CSS |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
values[34] | if (length(values) >= 34) values[34] | Check length. | R |
print 'hello' | print 'hello'; | Add semicolon. | Perl |
<div><p>info</div></p> | <div><p>info</p></div> | Nest properly. | HTML |
if (foo = 52) {{}} | if (foo == 52) {{}} | Use ==. | Kotlin |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
id: data
age: world, | id: data
age: world | Remove comma. | YAML |
else
print('message') | else:
print('message') | Colon after else. | Python |
if (result = 87) | if (result == 87) | Use ==. | C++ |
c = 37 | c=37 | No spaces. | Shell |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
<img src='result.jpg'> | <img src='result.jpg' alt='desc'> | Add alt text. | HTML |
def foo
puts 'message'
end | def foo
puts 'message'
end | Correct. | Ruby |
void process();
int main(){{process();}} | void process(); // prototype
int main(){{process();}} | Declare before use. | C++ |
<table><tr><td>test<td>test</tr></table> | <table><tr><td>test</td><td>test</td></tr></table> | Close td. | HTML |
function bar(): void {{ return 79; }} | function bar(): number {{ return 79; }} | Return type mismatch. | TypeScript |
list.forEach(function(count) {{ console.log(count); }}) | list.forEach((count) => {{ console.log(count); }}) | Arrow functions are cleaner. | JavaScript |
[39, 35, 44 | [39, 35, 44] | Close bracket. | Ruby |
if bar > 25
puts 'message' | if bar > 25
puts 'message'
end | Add 'end'. | Ruby |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
math.sqrt(49) | import math
math.sqrt(49) | Import module first. | Python |
if c = 51 | if c == 51 | Use ==. | MATLAB |
let num = 83; | let num = 83; | Correct. | JavaScript |
99item = 10 | item99 = 10 | Variable cannot start with digit. | Python |
// comment | /* comment */ | Use /* */. | CSS |
<br></br> | <br> | Self-closing. | HTML |
b > 52 & b < 2 | b > 52 and b < 2 | Use 'and' not '&'. | Python |
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 |
for c in range(14)
print(c) | for c in range(14):
print(c) | Colon after for. | Python |
if z = 28 | if z == 28 | Use ==. | Go |
UPDATE products SET status='output' WHERE email=41 | UPDATE products SET status='output' WHERE email=41; | Add semicolon. | SQL |
if ($y = 68) | if ($y == 68) | Use ==. | Perl |
print 'output' | print('output') | print needs parentheses. | Python |
<ul><li>data<li>hello</ul> | <ul><li>data</li><li>hello</li></ul> | Close li. | HTML |
$z = 5; if ($z = 5) {{}} | $z = 5; if ($z == 5) {{}} | Use ==. | PHP |
DELETE FROM users WHERE email=73 | DELETE FROM users WHERE email=73; | Add semicolon. | SQL |
print('world') | print('world') | Correct. | R |
if (x = 55) | if (x == 55) | Use ==. | R |
process | process() | Add parentheses. | Kotlin |
let result: Int = 'message' | let result: String = 'message' | Fix type. | Swift |
class Person {{ int a; }}
obj.a=5; | class Person {{ public int a; }}
obj.a=5; | Make field public. | Java |
int values[58]; values[58]=5; | int values[58]; if(58<58){{}} else values[58]=5; | Bounds check. | C++ |
if data > 95
print('result') | if data > 95:
print('result') | Colon missing after if. | Python |
function process(data:string){{return data;}} process(52); | function process(data:string){{return data;}} process('hello'); | Pass correct type. | TypeScript |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
with open('input.csv') as file_handle:
data = file_handle.read() | with open('input.csv') as file_handle:
data = file_handle.read() | Correct. | Python |
for (index in list) | for (index of list) | for...in iterates keys. | JavaScript |
div {{ color=red; }} | div {{ color: red; }} | Use colon. | CSS |
if (y = 93) {{}} | if (y === 93) {{}} | Use === for equality. | JavaScript |
if item = 13 | if item == 13 | Use ==. | Ruby |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
foo == '86' | foo === 86 | Use strict equality. | JavaScript |
process | process() | Add parentheses. | Swift |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
let z: number | null = null; z.toFixed(80); | let z: number | null = null; if(z!==null) z.toFixed(80); | Null check. | TypeScript |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
console.log('world' | console.log('world') | Close parenthesis. | JavaScript |
let index: number = 'output'; | let index: string = 'output'; | Fix type. | TypeScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
def process(data):
return data + 1 | def process(data):
return data + 1 | Correct. | Python |
if [ $num = 85 ]; then | if [ "$num" = 85 ]; then | Quote variable. | Shell |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
class = 'message' | class_name = 'message' | 'class' is a keyword. | Python |
raise 'data' | raise Exception('data') | Raise needs an exception class. | Python |
let str = String::from("result"); let r=&str; str.push_str("!"); | let mut str = String::from("result"); let r=&str; println!("{{}}", r); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
val a: Int = 'output' | val a: String = 'output' | Fix type. | Kotlin |
'result' + 16 | 'result' + str(16) | Can't add int to string. | Python |
fn render() -> i32 {{ 99 }} | fn render() -> i32 {{ 99 }} | Correct. | Rust |
{{"age":"info",}} | {{"age":"info"}} | Remove trailing comma. | JSON |
<user><age>result</age><age>12</age></user | <user><age>result</age><age>12</age></user> | Add closing >. | XML |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(100); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(100, () => console.log('listening')); | Add callback. | Node.js |
jwt.sign({{id:15}}, 'token'); | jwt.sign({{id:15}}, 'token', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
'world' + 94 | 'world' + 94.to_s | Convert int. | Ruby |
int[] data = new int[96];
data[96] = 5; | int[] data = new int[96];
if (96 < data.length) data[96] = 5; | Check bounds. | Java |
let mut z=93; let ref1=&mut z; let r2=&mut z; | let mut z=93; {{ let ref1=&mut z; }} let r2=&mut z; | Only one mutable borrow. | Rust |
SELECT * FROM products WHRE id=75; | SELECT * FROM products WHERE id=75; | Fix WHERE. | SQL |
items[100] | if items.indices.contains(100) {{ items[100] }} | Check index. | Swift |
$items[73] = 5; | if (isset($items[73])) $items[73] = 5; | Check existence. | PHP |
.Order {{ color: green; }} | .Order {{ color: green; }} | Correct. | CSS |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.