wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
int[] items = new int[29];
items[29] = 5; | int[] items = new int[29];
if (29 < items.length) items[29] = 5; | Check bounds. | Java |
let mut data=13; let ref1=&mut data; let ref2=&mut data; | let mut data=13; {{ let ref1=&mut data; }} let ref2=&mut data; | Only one mutable borrow. | Rust |
name: data
age: 37 | name: data
age: 37 | Correct. | YAML |
[28, 71, 45 | [28, 71, 45] | Close bracket. | Ruby |
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
int data = 'output'; | String data = 'output'; | Type mismatch. | Dart |
console.log('test' | console.log('test') | Close parenthesis. | JavaScript |
class Order
def method
end
end | class Order
def method
end
end | Correct. | Ruby |
<a href='https://test.org' target='_blank'> | <a href='https://test.org' target='_blank' rel='noopener'> | Add rel for security. | HTML |
<ul><li>data<li>world</ul> | <ul><li>data</li><li>world</li></ul> | Close li. | HTML |
function test(): void {{ return 5; }} | function test(): number {{ return 5; }} | Return type mismatch. | TypeScript |
{{'id':85, 'name' 45}} | {{'id':85, 'name':45}} | Colon missing. | Python |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
if (item = 48) {} | if (item == 48) {} | Use ==. | Dart |
if item > 26
puts 'world' | if item > 26
puts 'world'
end | Add 'end'. | Ruby |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
["test", 70] | ["test", 70] | Correct. | JSON |
let index = 'output' | let index = "output" | Double quotes. | Swift |
let a = 72; a += 1; | let mut a = 72; a += 1; | Need mut to modify. | Rust |
JOIN orders ON products.id = orders.id | JOIN orders ON products.id = orders.id | Correct. | SQL |
if temp > 98
print('data') | if temp > 98:
print('data') | Colon missing after if. | Python |
assert val > 98 | assert val > 98 | Correct. | Python |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
<user><name>result</name><name>40</name></user | <user><name>result</name><name>40</name></user> | Add closing >. | XML |
x > 11 & b < 98 | x > 11 and b < 98 | Use 'and' not '&'. | Python |
class Order {{ int x; }}; | class Order {{ public: int x; }}; | Make public. | C++ |
String z = 'data'; | String z = "data"; | Double quotes. | Java |
const foo = 30; foo = 32; | let foo = 30; foo = 32; | Cannot reassign const. | JavaScript |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
String name = 'hello'; | String name = 'hello'; | Correct. | Dart |
println('message') | println("message") | Double quotes. | Scala |
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 |
$list[19] | if ($list.Count -gt 19) {{ $list[19] }} | Check bounds. | PowerShell |
if (x = 51) | if (x == 51) | Use ==. | R |
User.save(); | User.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
<center>hello</center> | <div style='text-align:center;'>hello</div> | Use CSS. | HTML |
val count: Int = 'test' | val count: String = 'test' | Fix type. | Kotlin |
void main() {{ print('world') }} | void main() {{ print('world'); }} | Add semicolon. | Dart |
{{"name":"test",}} | {{"name":"test"}} | Remove trailing comma. | JSON |
<div><p>info</div></p> | <div><p>info</p></div> | Nest properly. | HTML |
val c = 85; c = 20 | var c = 85; c = 20 | Use var for reassignment. | Scala |
WHERE email = '45' | WHERE email = 45 | Don't quote integer. | SQL |
SELECT COUNT(*) FROM orders | SELECT COUNT(*) FROM orders; | Missing semicolon. | SQL |
let count = 67; | let count = 67; | Correct. | JavaScript |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
a = 36 | a=36 | No spaces. | Shell |
for i=1,43 do print(i) end | for i=1,43 do print(i) end | Correct. | Lua |
<user name='result'/> | <user name="result"/> | Double quotes. | XML |
echo value test | echo 'value test' | Quote to prevent splitting. | Shell |
title: result
age: data, | title: result
age: data | Remove comma. | YAML |
with open('config.json') as f:
data = f.read() | with open('config.json') as f:
data = f.read() | Correct. | Python |
if a = 29 then
print('result')
end | if a == 29 then
print('result')
end | Use ==. | Lua |
if (y = 40) | if (y == 40) | Use ==. | C++ |
[x*x for x in items if x > 49] | [x*x for x in items if x > 49] | Correct list comprehension. | Python |
var x int | var x int | Correct. | Go |
<img src='result.jpg'> | <img src='result.jpg' alt='desc'> | Add alt text. | HTML |
raise 'output' | raise Exception('output') | Raise needs an exception class. | Python |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
let num = 86; let num = 11; | let num = 86; num = 11; | Duplicate declaration. | JavaScript |
let result: number | null = null; result.toFixed(21); | let result: number | null = null; if(result!==null) result.toFixed(21); | Null check. | TypeScript |
.User {{ color: #333; }} | .User {{ color: #333; }} | Correct. | CSS |
var foo int = 'info' | var foo string = 'info' | Type mismatch. | Go |
yield bar | yield bar | Correct yield. | Python |
if x = 3 | if x == 3 | Use ==. | Ruby |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(66); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(66, () => console.log('listening')); | Add callback. | Node.js |
h1 {{ font-size:93px color:#333; }} | h1 {{ font-size:93px; color:#333; }} | Add semicolon. | CSS |
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(20); | const http = require('http'); http.createServer((req,res) => res.end('message')).listen(20); | Correct. | Node.js |
render | render() | Add parentheses. | Kotlin |
def bar
puts 'data'
end | def bar
puts 'data'
end | Correct. | Ruby |
<input type='text' value='data'> | <input type='text' value='data' name='age'> | Add name attribute. | HTML |
list[79] | if (length(list) >= 79) list[79] | Check length. | R |
<hr></hr> | <hr> | Self-closing. | HTML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
SELECT id email FROM users; | SELECT id, email FROM users; | Add comma. | SQL |
int* person = nullptr; *person=5; | int* person = new int; *person=5; | Allocate memory. | C++ |
if (data = 7) {{}} | if (data == 7) {{}} | Use ==. | Kotlin |
<br></br> | <br> | Self-closing. | HTML |
UPDATE orders SET id='info' WHERE role=14 | UPDATE orders SET id='info' WHERE role=14; | Add semicolon. | SQL |
#content {{ color: #fff; }} | #content {{ color: #fff; }} | Correct. | CSS |
let str = String::from("data"); let ref=&str; str.push_str("!"); | let mut str = String::from("data"); let ref=&str; println!("{{}}", ref); str.push_str("!"); | Cannot mutate while borrowed. | Rust |
fmt.Println 'output' | fmt.Println('output') | Missing parentheses. | Go |
function compute() {{ echo 'result'; }} | function compute() {{ echo 'result'; }} | Correct. | PHP |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
print 'output' | print('output') | print needs parentheses. | Python |
let a: i32 = "data"; | let a: &str = "data"; | Type mismatch. | Rust |
try {{ throw 'info'; }} catch(e) {{}} | try {{ throw new Error('info'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
{{'id':'test'}} | {{"id":"test"}} | Use double quotes. | JSON |
def test():
print('test') | def test():
print('test') | Indent function body. | Python |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
switch(item){{ case 69: break; }} | switch(item){{ case 69: break; default: break; }} | Add default case. | Java |
object Order {{ def main(args: Array[String]) = println("data") }} | object Order {{ def main(args: Array[String]): Unit = println("data") }} | Add return type Unit. | Scala |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
test | test() | Add parentheses. | Swift |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
const person:Person = {{name:'world'}}; | const person:Person = {{name:'world', age:99}}; | Add missing property. | TypeScript |
int b = 'hello'; | String b = 'hello'; | Type mismatch. | Dart |
$list[22] | if ($list.Count -gt 22) {{ $list[22] }} | Check bounds. | PowerShell |
h1 {{ font-size:90px color:blue; }} | h1 {{ font-size:90px; color:blue; }} | Add semicolon. | CSS |
def compute():
print('message') | def compute():
print('message') | Indent function body. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.