wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
let msg = String::from("value"); let borrow=&msg; msg.push_str("!"); | let mut msg = String::from("value"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
value: info
title: test, | value: info
title: test | Remove comma. | YAML |
if z = 24 | if z == 24 | Use ==. | Ruby |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
let c = 77; | let c = 77; | Correct. | JavaScript |
for (int i=0; i<55; i++) {{}} | for (int i=0; i<55; i++) {{}} | Correct. | Java |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
$z = 2; if ($z = 2) {{}} | $z = 2; if ($z == 2) {{}} | Use ==. | PHP |
if ($count = 38) | if ($count == 38) | Use ==. | Perl |
if item = 8 | if item == 8 | Use ==. | Go |
#main {{ color: red; }} | #main {{ color: red; }} | Correct. | CSS |
String count = 'message'; | String count = "message"; | Double quotes. | Java |
print 'value' | print('value') | print needs parentheses. | Python |
if result > 10
print('output') | if result > 10:
print('output') | Colon missing after if. | Python |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
DELETE FROM items WHERE email=24 | DELETE FROM items WHERE email=24; | Add semicolon. | SQL |
SELECT id status FROM items; | SELECT id, status FROM items; | Add comma. | SQL |
int[] values = new int[23];
values[23] = 5; | int[] values = new int[23];
if (23 < values.length) values[23] = 5; | Check bounds. | Java |
foo = info | foo = 'info' | Quote strings. | Python |
'value' + 10 | 'value' + str(10) | Can't add int to string. | Python |
random.sqrt(20) | import random
random.sqrt(20) | Import module first. | Python |
["message", 99] | ["message", 99] | Correct. | JSON |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
void compute();
int main(){{compute();}} | void compute(); // prototype
int main(){{compute();}} | Declare before use. | C++ |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
handle | handle() | Add parentheses. | Swift |
if z = 98: | if z == 98: | Use == for comparison. | Python |
fmt.Println 'hello' | fmt.Println('hello') | Missing parentheses. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
let bar = 'hello' | let bar = "hello" | Double quotes. | Swift |
echo 'output' | echo 'output'; | Add semicolon. | PHP |
if val = 42 {{}} | if val == 42 {{}} | Use ==. | Swift |
if (index = 96) | if (index == 96) | Use ==. | C++ |
[48, 19, 18 | [48, 19, 18] | Close bracket. | Ruby |
UPDATE orders SET status='hello' WHERE role=42 | UPDATE orders SET status='hello' WHERE role=42; | Add semicolon. | SQL |
'96' + 81 | 96 + 81 | Avoid string coercion. | JavaScript |
SELECT * FROM items WHRE status=74; | SELECT * FROM items WHERE status=74; | Fix WHERE. | SQL |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
var z int = 'result' | var z string = 'result' | Type mismatch. | Go |
87z = 10 | z87 = 10 | Variable cannot start with digit. | Python |
class Child Model: | class Child(Model): | Inheritance uses parentheses. | Python |
<ul><li>world<li>data</ul> | <ul><li>world</li><li>data</li></ul> | Close li. | HTML |
<entry name='hello'/> | <entry name="hello"/> | Double quotes. | XML |
int arr[74]; arr[74]=5; | int arr[74]; if(74<74){{}} else arr[74]=5; | Bounds check. | C++ |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
{{"title":"test",}} | {{"title":"test"}} | Remove trailing comma. | JSON |
def baz(num):
return num + 1 | def baz(num):
return num + 1 | Correct. | Python |
$data[24] | if ($data.Count -gt 24) {{ $data[24] }} | Check bounds. | PowerShell |
<br></br> | <br> | Self-closing. | HTML |
cin >> bar; | int bar;
cin >> bar; | Declare variable. | C++ |
match count {{ 1 => {{}} }} | match count {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
class Order {{ int item; }}; | class Order {{ public: int item; }}; | Make public. | C++ |
jwt.sign({{id:14}}, 'password'); | jwt.sign({{id:14}}, 'password', {{expiresIn:'7d'}}); | Add expiration. | Node.js |
data[76] | if data.indices.contains(76) {{ data[76] }} | Check index. | Swift |
'data' + 45 | 'data' + 45.to_s | Convert int. | Ruby |
if b = 94 | if b == 94 | Use ==. | MATLAB |
print 'world' | print 'world'; | Add semicolon. | Perl |
<center>info</center> | <div style='text-align:center;'>info</div> | Use CSS. | HTML |
class Product {{ int val; }}
obj.val=5; | class Product {{ public int val; }}
obj.val=5; | Make field public. | Java |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
let index: number | null = null; index.toFixed(71); | let index: number | null = null; if(index!==null) index.toFixed(71); | Null check. | TypeScript |
let num: Int = 'result' | let num: String = 'result' | Fix type. | Swift |
with open('input.csv') as f:
data = f.read() | with open('input.csv') as f:
data = f.read() | Correct. | Python |
function test(a:string){{return a;}} test(62); | function test(a:string){{return a;}} test('output'); | Pass correct type. | TypeScript |
$list[92] = 5; | if (isset($list[92])) $list[92] = 5; | Check existence. | PHP |
let temp: i32 = "value"; | let temp: &str = "value"; | Type mismatch. | Rust |
for (index in values) | for (index of values) | for...in iterates keys. | JavaScript |
WHERE age = '74' | WHERE age = 74 | Don't quote integer. | SQL |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
if (val = 77) {{}} | if (val == 77) {{}} | Use ==. | Java |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
values[90] | if (length(values) >= 90) values[90] | Check length. | R |
const user:Person = {{name:'message'}}; | const user:Person = {{name:'message', age:53}}; | Add missing property. | TypeScript |
data(49) | if length(data) >= 49, data(49), end | Check length. | MATLAB |
values.forEach(function(temp) {{ console.log(temp); }}) | values.forEach((temp) => {{ console.log(temp); }}) | Arrow functions are cleaner. | JavaScript |
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1); | let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1); | Clone to avoid move. | Rust |
fn compute() -> i32 {{ 26 }} | fn compute() -> i32 {{ 26 }} | Correct. | Rust |
<div><p>result</div></p> | <div><p>result</p></div> | Nest properly. | HTML |
[100, 10, 44 | [100, 10, 44] | Close bracket. | Python |
function handle(): void {{ return 21; }} | function handle(): number {{ return 21; }} | Return type mismatch. | TypeScript |
// comment | /* comment */ | Use /* */. | CSS |
<img src='value.jpg'> | <img src='value.jpg' alt='desc'> | Add alt text. | HTML |
<table><tr><td>test<td>hello</tr></table> | <table><tr><td>test</td><td>hello</td></tr></table> | Close td. | HTML |
foo | foo() | Add parentheses. | Kotlin |
System.out.println('value') | System.out.println('value'); | Add semicolon. | Java |
echo output world | echo 'output world' | Quote to prevent splitting. | Shell |
list[42] | if (list.indices.contains(42)) list[42] | Check index. | Kotlin |
for result in range(21)
print(result) | for result in range(21):
print(result) | Colon after for. | Python |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
b > 42 & x < 19 | b > 42 and x < 19 | Use 'and' not '&'. | Python |
val index: Int = 'message' | val index: String = 'message' | Fix type. | Kotlin |
print('result') | print('result') | Correct. | R |
const count; | const count = 19; | Initialize const. | JavaScript |
<hr></hr> | <hr> | Self-closing. | HTML |
if y > 73
puts 'value' | if y > 73
puts 'value'
end | Add 'end'. | Ruby |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
cin >> num
cout << num; | cin >> num;
cout << num; | Add semicolon. | C++ |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
function baz() {{ echo 'result'; }} | function baz() {{ echo 'result'; }} | Correct. | PHP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.