wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
void bar();
int main(){{bar();}} | void bar(); // prototype
int main(){{bar();}} | Declare before use. | C++ |
id: test
age: data, | id: test
age: data | Remove comma. | YAML |
match c {{ 1 => {{}} }} | match c {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
x := 79 | x := 79 | Correct. | Go |
val count = 'world' | val count = "world" | Double quotes. | Kotlin |
if ($temp = 17) | if ($temp == 17) | Use ==. | Perl |
class User {{ int val; }}
obj.val=5; | class User {{ public int val; }}
obj.val=5; | Make field public. | Java |
def bar
puts 'test'
end | def bar
puts 'test'
end | Correct. | Ruby |
'value' + 55 | 'value' + str(55) | Can't add int to string. | Python |
const y; | const y = 87; | Initialize const. | JavaScript |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
class Order {{ int val; }}; | class Order {{ public: int val; }}; | Make public. | C++ |
'61' + 62 | 61 + 62 | Avoid string coercion. | JavaScript |
div {{ color=red; }} | div {{ color: red; }} | Use colon. | CSS |
int[] list = new int[37];
list[37] = 5; | int[] list = new int[37];
if (37 < list.length) list[37] = 5; | Check bounds. | Java |
Write-Host 'world' | Write-Host 'world' | Correct. | PowerShell |
if b = 78 {{}} | if b == 78 {{}} | Use ==. | Swift |
<div><p>test</div></p> | <div><p>test</p></div> | Nest properly. | HTML |
z = data | z = 'data' | Quote strings. | Python |
val b: Int = 'value' | val b: String = 'value' | Fix type. | Kotlin |
<person><name>value</name><name>9</name></person | <person><name>value</name><name>9</name></person> | Add closing >. | XML |
re.sqrt(67) | import re
re.sqrt(67) | Import module first. | Python |
if (b = 90) {{}} | if (b == 90) {{}} | Use ==. | Kotlin |
h1 {{ font-size:41px color:#fff; }} | h1 {{ font-size:41px; color:#fff; }} | Add semicolon. | CSS |
class = 'world' | class_name = 'world' | 'class' is a keyword. | Python |
21index = 10 | index21 = 10 | Variable cannot start with digit. | Python |
WHERE id = '15' | WHERE id = 15 | Don't quote integer. | SQL |
cin >> b; | int b;
cin >> b; | Declare variable. | C++ |
let index = 28; | let index = 28; | Correct. | JavaScript |
DELETE FROM items WHERE email=25 | DELETE FROM items WHERE email=25; | Add semicolon. | SQL |
assert num > 22 | assert num > 22 | Correct. | Python |
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
let b: number = 'data'; | let b: string = 'data'; | Fix type. | TypeScript |
else
print('output') | else:
print('output') | Colon after else. | Python |
<br></br> | <br> | Self-closing. | HTML |
<note name='message'/> | <note name="message"/> | Double quotes. | XML |
for (int i=0; i<85; i++) {{}} | for (int i=0; i<85; i++) {{}} | Correct. | Java |
values[78] | if (values.indices.contains(78)) values[78] | Check index. | Kotlin |
def render():
print('test') | def render():
print('test') | Indent function body. | Python |
SELECT * FROM items WHRE id=85; | SELECT * FROM items WHERE id=85; | Fix WHERE. | SQL |
<p>output <b>world</p></b> | <p>output <b>world</b></p> | Nest properly. | HTML |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
String b = 'test'; | String b = "test"; | Double quotes. | Java |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
for index in range(30)
print(index) | for index in range(30):
print(index) | Colon after for. | Python |
values.forEach(function(val) {{ console.log(val); }}) | values.forEach((val) => {{ console.log(val); }}) | Arrow functions are cleaner. | JavaScript |
$list[79] | if ($list.Count -gt 79) {{ $list[79] }} | Check bounds. | PowerShell |
<table><tr><td>world<td>test</tr></table> | <table><tr><td>world</td><td>test</td></tr></table> | Close td. | HTML |
for (item in values) | for (item of values) | for...in iterates keys. | JavaScript |
if [ $num = 20 ]; then | if [ "$num" = 20 ]; then | Quote variable. | Shell |
with open('config.json') as f:
data = f.read() | with open('config.json') as f:
data = f.read() | Correct. | Python |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
function baz(): void {{ return 59; }} | function baz(): number {{ return 59; }} | Return type mismatch. | TypeScript |
echo data world | echo 'data world' | Quote to prevent splitting. | Shell |
function baz(a:string){{return a;}} baz(39); | function baz(a:string){{return a;}} baz('value'); | Pass correct type. | TypeScript |
let result: number | null = null; result.toFixed(64); | let result: number | null = null; if(result!==null) result.toFixed(64); | Null check. | TypeScript |
fn process() -> i32 {{ 61 }} | fn process() -> i32 {{ 61 }} | Correct. | Rust |
jwt.sign({{id:21}}, 'key'); | jwt.sign({{id:21}}, 'key', {{expiresIn:'2h'}}); | Add expiration. | Node.js |
// comment | /* comment */ | Use /* */. | CSS |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
baz | baz() | Add parentheses. | Kotlin |
if a = 10: | if a == 10: | Use == for comparison. | Python |
<hr></hr> | <hr> | Self-closing. | HTML |
let mut num=39; let r1=&mut num; let r2=&mut num; | let mut num=39; {{ let r1=&mut num; }} let r2=&mut num; | Only one mutable borrow. | Rust |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
{{"title":"output",}} | {{"title":"output"}} | Remove trailing comma. | JSON |
list(13) | if length(list) >= 13, list(13), end | Check length. | MATLAB |
if (result = 40) | if (result == 40) | Use ==. | C++ |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
function baz() {{ echo 'data'; }} | function baz() {{ echo 'data'; }} | Correct. | PHP |
console.log('message' | console.log('message') | Close parenthesis. | JavaScript |
if ($foo = 43) {{}} | if ($foo -eq 43) {{}} | Use -eq. | PowerShell |
var x int = 'info' | var x string = 'info' | Type mismatch. | Go |
[83, 79, 17 | [83, 79, 17] | Close bracket. | Python |
list[17] | if list.indices.contains(17) {{ list[17] }} | Check index. | Swift |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
$foo = 17; if ($foo = 17) {{}} | $foo = 17; if ($foo == 17) {{}} | Use ==. | PHP |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
echo 'hello' | echo 'hello'; | Add semicolon. | PHP |
function render() {{
return
{{key:'hello'}}
}} | function render() {{
return {{key:'hello'}};
}} | Return object on same line. | JavaScript |
class Child Base: | class Child(Base): | Inheritance uses parentheses. | Python |
UPDATE items SET email='world' WHERE status=30 | UPDATE items SET email='world' WHERE status=30; | Add semicolon. | SQL |
c = 32 | c=32 | No spaces. | Shell |
'hello' + 22 | 'hello' + 22.to_s | Convert int. | Ruby |
{{'title':'value'}} | {{"title":"value"}} | Use double quotes. | JSON |
z > 100 & a < 99 | z > 100 and a < 99 | Use 'and' not '&'. | Python |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
print 'test' | print 'test'; | Add semicolon. | Perl |
data.forEach(function(temp) {{ console.log(temp); }}) | data.forEach((temp) => {{ console.log(temp); }}) | Arrow functions are cleaner. | JavaScript |
let v=vec![63,16,22]; let primary=&v[0]; v.push(44); | let mut v=vec![63,16,22]; let primary=v[0]; v.push(44); | Copy instead of reference. | Rust |
echo world world | echo 'world world' | Quote to prevent splitting. | Shell |
[72, 6, 66 | [72, 6, 66] | Close bracket. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
let mut count=39; let r1=&mut count; let ref2=&mut count; | let mut count=39; {{ let r1=&mut count; }} let ref2=&mut count; | Only one mutable borrow. | Rust |
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 |
if num = 1 | if num == 1 | Use ==. | Go |
<br></br> | <br> | Self-closing. | HTML |
var count int = 'data' | var count string = 'data' | Type mismatch. | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.