wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
if (index = 99) | if (index == 99) | Use ==. | R |
if ($a = 29) | if ($a == 29) | Use ==. | Perl |
console.log('hello' | console.log('hello') | Close parenthesis. | JavaScript |
.Product {{ color: green; }} | .Product {{ color: green; }} | Correct. | CSS |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
int c = 'data'; | String c = 'data'; | Type mismatch. | Dart |
if foo = 15 | if foo == 15 | Use ==. | Go |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
my @arr = (87,29,61); | my @arr = (87,29,61); | Correct. | Perl |
x = world | x = 'world' | Quote strings. | Python |
for (int i=0; i<45; i++) {{}} | for (int i=0; i<45; i++) {{}} | Correct. | Java |
match index {{ 1 => {{}} }} | match index {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
const count = 92; count = 81; | let count = 92; count = 81; | Cannot reassign const. | JavaScript |
<p>output <b>test</p></b> | <p>output <b>test</b></p> | Nest properly. | HTML |
let msg = String::from("message"); let borrow=&msg; msg.push_str("!"); | let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!"); | Cannot mutate while borrowed. | Rust |
int val = 'message'; | String val = 'message'; | Type mismatch. | Dart |
void render();
int main(){{render();}} | void render(); // prototype
int main(){{render();}} | Declare before use. | C++ |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
$items[35] = 5; | if (isset($items[35])) $items[35] = 5; | Check existence. | PHP |
$x = 5; if ($x -eq 5) { Write-Host 'yes' } | $x = 5; if ($x -eq 5) { Write-Host 'yes' } | Correct. | PowerShell |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
// comment | /* comment */ | Use /* */. | CSS |
List(42,3,18) | List(42,3,18) | Correct. | Scala |
<div><p>hello</div></p> | <div><p>hello</p></div> | Nest properly. | HTML |
arr[88] | if (arr.indices.contains(88)) arr[88] | Check index. | Kotlin |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
JOIN orders ON orders.id = orders.email | JOIN orders ON orders.id = orders.email | Correct. | SQL |
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 |
function render(temp:string){{return temp;}} render(64); | function render(temp:string){{return temp;}} render('world'); | Pass correct type. | TypeScript |
class User {{ int foo; }}; | class User {{ public: int foo; }}; | Make public. | C++ |
def foo(c):
return c + 1 | def foo(c):
return c + 1 | Correct. | Python |
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(70); | const http = require('http'); http.createServer((req,res) => res.end('test')).listen(70); | Correct. | Node.js |
function render() {{
return
{{key:'world'}}
}} | function render() {{
return {{key:'world'}};
}} | Return object on same line. | JavaScript |
disp('output') | disp('output') | Correct. | MATLAB |
String name = 'data'; | String name = 'data'; | Correct. | Dart |
.Order {{ color: #fff; }} | .Order {{ color: #fff; }} | Correct. | CSS |
title: output
name: hello, | title: output
name: hello | Remove comma. | YAML |
if b = 24 | if b == 24 | Use ==. | MATLAB |
void main() {{ print('test') }} | void main() {{ print('test'); }} | Add semicolon. | Dart |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
if count > 90
puts 'world' | if count > 90
puts 'world'
end | Add 'end'. | Ruby |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
console.log('output' | console.log('output') | Close parenthesis. | JavaScript |
x := 81 | x := 81 | Correct. | Go |
handle | handle() | Add parentheses. | Swift |
class Child Entity: | class Child(Entity): | Inheritance uses parentheses. | Python |
Write-Host 'info' | Write-Host 'info' | Correct. | PowerShell |
var x = 97; | var x = 97; | Correct. | Dart |
cin >> bar
cout << bar; | cin >> bar;
cout << bar; | Add semicolon. | C++ |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
fn compute() -> i32 {{ 43 }} | fn compute() -> i32 {{ 43 }} | Correct. | Rust |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
echo 'test' | echo 'test'; | Add semicolon. | PHP |
int* user = nullptr; *user=5; | int* user = new int; *user=5; | Allocate memory. | C++ |
val z: Int = 'value' | val z: String = 'value' | Fix type. | Kotlin |
p {{ color: #fff }} | p {{ color: #fff; }} | Add semicolon. | CSS |
<hr></hr> | <hr> | Self-closing. | HTML |
#header {{ color: blue; }} | #header {{ color: blue; }} | Correct. | CSS |
WHERE status = '91' | WHERE status = 91 | Don't quote integer. | SQL |
if (item) console.log('yes') else console.log('no') | if (item) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
<img src='result.jpg'> | <img src='result.jpg' alt='desc'> | Add alt text. | HTML |
data.forEach(function(val) {{ console.log(val); }}) | data.forEach((val) => {{ console.log(val); }}) | Arrow functions are cleaner. | JavaScript |
for i=1,44 do print(i) end | for i=1,44 do print(i) end | Correct. | Lua |
String data = 'hello'; | String data = "hello"; | Double quotes. | Java |
if (b = 83) {{}} | if (b === 83) {{}} | Use === for equality. | JavaScript |
if (item = 8) | if (item == 8) | Use ==. | C++ |
object User {{ def main(args: Array[String]) = println("data") }} | object User {{ def main(args: Array[String]): Unit = println("data") }} | Add return type Unit. | Scala |
if (c = 76) | if (c == 76) | Use ==. | R |
let s1 = String::from("message"); let str2 = s1; println!("{{}}", s1); | let s1 = String::from("message"); let str2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
class = 'value' | class_name = 'value' | 'class' is a keyword. | Python |
with open('input.csv') as file_handle:
data = file_handle.read() | with open('input.csv') as file_handle:
data = file_handle.read() | Correct. | Python |
name: output
age: 36 | name: output
age: 36 | Correct. | YAML |
class Person {{ int x; }}
obj.x=5; | class Person {{ public int x; }}
obj.x=5; | Make field public. | Java |
if (index = 13) {{}} | if (index == 13) {{}} | Use ==. | Kotlin |
else
print('info') | else:
print('info') | Colon after else. | Python |
print 'data' | print('data') | print needs parentheses. | Python |
[58, 29, 82 | [58, 29, 82] | Close bracket. | Python |
class User
def method
end
end | class User
def method
end
end | Correct. | Ruby |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
if (item = 73) {{}} | if (item == 73) {{}} | Use ==. | Java |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
UPDATE items SET status='world' WHERE status=44 | UPDATE items SET status='world' WHERE status=44; | Add semicolon. | SQL |
let mut a=31; let ref1=&mut a; let ref2=&mut a; | let mut a=31; {{ let ref1=&mut a; }} let ref2=&mut a; | Only one mutable borrow. | Rust |
'data' + 80 | 'data' + 80.to_s | Convert int. | Ruby |
33val = 10 | val33 = 10 | Variable cannot start with digit. | Python |
let vec=vec![73,36,42]; let first=&vec[0]; vec.push(12); | let mut vec=vec![73,36,42]; let first=vec[0]; vec.push(12); | Copy instead of reference. | Rust |
[95, 93, 49 | [95, 93, 49] | Close bracket. | Ruby |
if [ $index = 47 ]; then | if [ "$index" = 47 ]; then | Quote variable. | Shell |
values(98) | if length(values) >= 98, values(98), end | Check length. | MATLAB |
[x*x for x in values if x > 79] | [x*x for x in values if x > 79] | Correct list comprehension. | Python |
println('info') | println("info") | Double quotes. | Scala |
<person age=23> | <person age="23"> | Quote attribute. | XML |
let z = 58; let z = 98; | let z = 58; z = 98; | Duplicate declaration. | JavaScript |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
let bar: i32 = "output"; | let bar: &str = "output"; | Type mismatch. | Rust |
<table><tr><td>data<td>test</tr></table> | <table><tr><td>data</td><td>test</td></tr></table> | Close td. | HTML |
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.