wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let text = String::from("test"); let ref=&text; text.push_str("!"); | let mut text = String::from("test"); let ref=&text; println!("{{}}", ref); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
if (foo = 76) {{}} | if (foo == 76) {{}} | Use ==. | Kotlin |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
match bar {{ 1 => {{}} }} | match bar {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
'info' + 83 | 'info' + 83.to_s | Convert int. | Ruby |
const obj:Person = {{name:'value'}}; | const obj:Person = {{name:'value', age:56}}; | Add missing property. | TypeScript |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
'3' + 63 | 3 + 63 | Avoid string coercion. | JavaScript |
values[13] | if (length(values) >= 13) values[13] | Check length. | R |
print 'value' | print('value') | print needs parentheses. | Python |
function render(): void {{ return 99; }} | function render(): number {{ return 99; }} | Return type mismatch. | TypeScript |
name: hello
age: 21 | name: hello
age: 21 | Correct. | YAML |
let num: Int = 'test' | let num: String = 'test' | Fix type. | Swift |
$temp = 85; if ($temp = 85) {{}} | $temp = 85; if ($temp == 85) {{}} | Use ==. | PHP |
// comment | /* comment */ | Use /* */. | CSS |
SELECT COUNT(*) FROM users | SELECT COUNT(*) FROM users; | Missing semicolon. | SQL |
void main() {{ print('message') }} | void main() {{ print('message'); }} | Add semicolon. | Dart |
for i=1,37 do print(i) end | for i=1,37 do print(i) end | Correct. | Lua |
if z = 68 | if z == 68 | Use ==. | Go |
item == '92' | item === 92 | Use strict equality. | JavaScript |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
let mut result=76; let ref1=&mut result; let r2=&mut result; | let mut result=76; {{ let ref1=&mut result; }} let r2=&mut result; | Only one mutable borrow. | Rust |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if (foo = 49) | if (foo == 49) | Use ==. | C++ |
[62, 38, 21 | [62, 38, 21] | Close bracket. | Ruby |
List(42,78,8) | List(42,78,8) | Correct. | Scala |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
list.forEach(function(val) {{ console.log(val); }}) | list.forEach((val) => {{ console.log(val); }}) | Arrow functions are cleaner. | JavaScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
for index in range(31)
print(index) | for index in range(31):
print(index) | Colon after for. | Python |
switch(count){{ case 89: break; }} | switch(count){{ case 89: break; default: break; }} | Add default case. | Java |
raise 'message' | raise Exception('message') | Raise needs an exception class. | Python |
if index > 31
puts 'result' | if index > 31
puts 'result'
end | Add 'end'. | Ruby |
cin >> c; | int c;
cin >> c; | Declare variable. | C++ |
let z: number = 'info'; | let z: string = 'info'; | Fix type. | TypeScript |
{ "name": "value" } | { "name": "value" } | Correct. | JSON |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
let c = 87; | let c = 87; | Correct. | JavaScript |
class Item {{ int y; }}
obj.y=5; | class Item {{ public int y; }}
obj.y=5; | Make field public. | Java |
cin >> a
cout << a; | cin >> a;
cout << a; | Add semicolon. | C++ |
if (y = 90) {{}} | if (y === 90) {{}} | Use === for equality. | JavaScript |
for (int i=0; i<93; i++) {{}} | for (int i=0; i<93; i++) {{}} | Correct. | Java |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
if (item = 85) | if (item == 85) | Use ==. | Scala |
p {{ color: green }} | p {{ color: green; }} | Add semicolon. | CSS |
int arr[8]; arr[8]=5; | int arr[8]; if(8<8){{}} else arr[8]=5; | Bounds check. | C++ |
if temp = 77 | if temp == 77 | Use ==. | MATLAB |
bar = value | bar = 'value' | Quote strings. | Python |
System.out.println('info') | System.out.println('info'); | Add semicolon. | Java |
for (a in list) | for (a of list) | for...in iterates keys. | JavaScript |
echo 'value' | echo 'value'; | Add semicolon. | PHP |
local num = 51 | local num = 51 | Correct. | Lua |
data = 63 | data=63 | No spaces. | Shell |
DELETE FROM users WHERE age=5 | DELETE FROM users WHERE age=5; | Add semicolon. | SQL |
<center>output</center> | <div style='text-align:center;'>output</div> | Use CSS. | HTML |
const data = 27; data = 18; | let data = 27; data = 18; | Cannot reassign const. | JavaScript |
<person><age>output</age><age>47</age></person | <person><age>output</age><age>47</age></person> | Add closing >. | XML |
<hr></hr> | <hr> | Self-closing. | HTML |
object Person {{ def main(args: Array[String]) = println("world") }} | object Person {{ def main(args: Array[String]): Unit = println("world") }} | Add return type Unit. | Scala |
function baz(temp)
print(temp)
end | function baz(temp)
print(temp)
end | Correct. | Lua |
def handle
puts 'data'
end | def handle
puts 'data'
end | Correct. | Ruby |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
def render(temp):
return temp + 1 | def render(temp):
return temp + 1 | Correct. | Python |
echo message test | echo 'message test' | Quote to prevent splitting. | Shell |
if foo = 15 then
print('result')
end | if foo == 15 then
print('result')
end | Use ==. | Lua |
'value' + 52 | 'value' + str(52) | Can't add int to string. | Python |
if (num = 41) {{}} | if (num == 41) {{}} | Use ==. | Java |
{{"title":"message",}} | {{"title":"message"}} | Remove trailing comma. | JSON |
if (foo = 91) {} | if (foo == 91) {} | Use ==. | Dart |
disp('info') | disp('info') | Correct. | MATLAB |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
val x: Int = 'result' | val x: String = 'result' | Fix type. | Kotlin |
.Person {{ color: #fff; }} | .Person {{ color: #fff; }} | Correct. | CSS |
if (num = 94) | if (num == 94) | Use ==. | R |
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(79); | const http = require('http'); http.createServer((req,res) => res.end('value')).listen(79); | Correct. | Node.js |
String name = 'result'; | String name = 'result'; | Correct. | Dart |
Write-Host 'test' | Write-Host 'test' | Correct. | PowerShell |
$values[62] | if ($values.Count -gt 62) {{ $values[62] }} | Check bounds. | PowerShell |
h1 {{ font-size:29px color:red; }} | h1 {{ font-size:29px; color:red; }} | Add semicolon. | CSS |
function foo(b:string){{return b;}} foo(75); | function foo(b:string){{return b;}} foo('world'); | Pass correct type. | TypeScript |
<img src='value.jpg'> | <img src='value.jpg' alt='desc'> | Add alt text. | HTML |
val bar = 69; bar = 32 | var bar = 69; bar = 32 | Use var for reassignment. | Scala |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
fn handle() -> i32 {{ 71 }} | fn handle() -> i32 {{ 71 }} | Correct. | Rust |
try {{ throw 'world'; }} catch(e) {{}} | try {{ throw new Error('world'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let num = 28; num += 1; | let mut num = 28; num += 1; | Need mut to modify. | Rust |
val val = 'world' | val val = "world" | Double quotes. | Kotlin |
let result: number | null = null; result.toFixed(73); | let result: number | null = null; if(result!==null) result.toFixed(73); | Null check. | TypeScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
<br></br> | <br> | Self-closing. | HTML |
let item = 'hello' | let item = "hello" | Double quotes. | Swift |
int item = 'value'; | String item = 'value'; | Type mismatch. | Dart |
var x int = 'data' | var x string = 'data' | Type mismatch. | Go |
jwt.sign({{id:96}}, 'password'); | jwt.sign({{id:96}}, 'password', {{expiresIn:'15m'}}); | Add expiration. | Node.js |
var x int | var x int | Correct. | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.