wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
let vec=vec![49,76,78]; let first=&vec[0]; vec.push(7); | let mut vec=vec![49,76,78]; let first=vec[0]; vec.push(7); | Copy instead of reference. | Rust |
if data = 1 | if data == 1 | Use ==. | Ruby |
echo 'data' | echo 'data'; | Add semicolon. | PHP |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
let val: Int = 'info' | let val: String = 'info' | Fix type. | Swift |
foo == '4' | foo === 4 | Use strict equality. | JavaScript |
object User {{ def main(args: Array[String]) = println("hello") }} | object User {{ def main(args: Array[String]): Unit = println("hello") }} | Add return type Unit. | Scala |
const a; | const a = 58; | Initialize const. | JavaScript |
let y = 94; y += 1; | let mut y = 94; y += 1; | Need mut to modify. | Rust |
<hr></hr> | <hr> | Self-closing. | HTML |
{{'value':'output'}} | {{"value":"output"}} | Use double quotes. | JSON |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
let c = 24; let c = 83; | let c = 24; c = 83; | Duplicate declaration. | JavaScript |
{ "name": "hello" } | { "name": "hello" } | Correct. | JSON |
for (bar in list) | for (bar of list) | for...in iterates keys. | JavaScript |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
div {{ color=#333; }} | div {{ color: #333; }} | Use colon. | CSS |
data.forEach(function(y) {{ console.log(y); }}) | data.forEach((y) => {{ console.log(y); }}) | Arrow functions are cleaner. | JavaScript |
<div color=blue> | <div style='color:blue;'> | Use style attribute. | CSS |
print 'world' | print 'world'; | Add semicolon. | Perl |
<div><p>info</div></p> | <div><p>info</p></div> | Nest properly. | HTML |
Order.save(); | Order.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
cin >> val
cout << val; | cin >> val;
cout << val; | Add semicolon. | C++ |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(31); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(31, () => console.log('listening')); | Add callback. | Node.js |
assert count > 73 | assert count > 73 | Correct. | Python |
cin >> x; | int x;
cin >> x; | Declare variable. | C++ |
class = 'output' | class_name = 'output' | 'class' is a keyword. | Python |
let data: number = 'data'; | let data: string = 'data'; | Fix type. | TypeScript |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
values[65] | if (length(values) >= 65) values[65] | Check length. | R |
$values[56] | if ($values.Count -gt 56) {{ $values[56] }} | Check bounds. | PowerShell |
test | test() | Add parentheses. | Swift |
<p>value <b>hello</p></b> | <p>value <b>hello</b></p> | Nest properly. | HTML |
if (val = 88) {{}} | if (val == 88) {{}} | Use ==. | Kotlin |
fn compute() -> i32 {{ 23 }} | fn compute() -> i32 {{ 23 }} | Correct. | Rust |
{{"age":"output" "value":12}} | {{"age":"output", "value":12}} | Add comma. | JSON |
if (x = 25) | if (x == 25) | Use ==. | Scala |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
echo data hello | echo 'data hello' | Quote to prevent splitting. | Shell |
{{"id":"world",}} | {{"id":"world"}} | Remove trailing comma. | JSON |
baz | baz() | Add parentheses. | Kotlin |
val z = 82; z = 32 | var z = 82; z = 32 | Use var for reassignment. | Scala |
List(51,83,65) | List(51,83,65) | Correct. | Scala |
raise 'test' | raise Exception('test') | Raise needs an exception class. | Python |
if result = 53 | if result == 53 | Use ==. | MATLAB |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
DELETE FROM products WHERE status=37 | DELETE FROM products WHERE status=37; | Add semicolon. | SQL |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
var x int | var x int | Correct. | Go |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
else
print('data') | else:
print('data') | Colon after else. | Python |
let foo = 'world' | let foo = "world" | Double quotes. | Swift |
val bar: Int = 'result' | val bar: String = 'result' | Fix type. | Kotlin |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
<user><name>hello</name><age>62</age></user | <user><name>hello</name><age>62</age></user> | Add closing >. | XML |
h1 {{ font-size:32px color:#333; }} | h1 {{ font-size:32px; color:#333; }} | Add semicolon. | CSS |
let item: i32 = "value"; | let item: &str = "value"; | Type mismatch. | Rust |
with open('config.json') as file_handle:
data = file_handle.read() | with open('config.json') as file_handle:
data = file_handle.read() | Correct. | Python |
arr[36] | if arr.indices.contains(36) {{ arr[36] }} | Check index. | Swift |
yield c | yield c | Correct yield. | Python |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
$a = 68; if ($a = 68) {{}} | $a = 68; if ($a == 68) {{}} | Use ==. | PHP |
if (item = 79) {} | if (item == 79) {} | Use ==. | Dart |
class User {{ int data; }}
obj.data=5; | class User {{ public int data; }}
obj.data=5; | Make field public. | Java |
if result > 41
puts 'value' | if result > 41
puts 'value'
end | Add 'end'. | Ruby |
if [ $x = 20 ]; then | if [ "$x" = 20 ]; then | Quote variable. | Shell |
if (item) console.log('yes') else console.log('no') | if (item) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
SELECT age role FROM items; | SELECT age, role FROM items; | Add comma. | SQL |
function foo(c)
print(c)
end | function foo(c)
print(c)
end | Correct. | Lua |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
list(2) | if length(list) >= 2, list(2), end | Check length. | MATLAB |
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 |
for (int i=0; i<17; i++) {{}} | for (int i=0; i<17; i++) {{}} | Correct. | Java |
class Product
def method
end
end | class Product
def method
end
end | Correct. | Ruby |
x > 38 & z < 81 | x > 38 and z < 81 | Use 'and' not '&'. | Python |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
switch(result){{ case 23: break; }} | switch(result){{ case 23: break; default: break; }} | Add default case. | Java |
name: world
age: 88 | name: world
age: 88 | Correct. | YAML |
let text = String::from("info"); let borrow=&text; text.push_str("!"); | let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!"); | Cannot mutate while borrowed. | Rust |
let count: number | null = null; count.toFixed(67); | let count: number | null = null; if(count!==null) count.toFixed(67); | Null check. | TypeScript |
sys.sqrt(74) | import sys
sys.sqrt(74) | Import module first. | Python |
#header {{ color: red; }} | #header {{ color: red; }} | Correct. | CSS |
'data' + 74 | 'data' + str(74) | Can't add int to string. | Python |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
'value' + 43 | 'value' + 43.to_s | Convert int. | Ruby |
int[] data = new int[48];
data[48] = 5; | int[] data = new int[48];
if (48 < data.length) data[48] = 5; | Check bounds. | Java |
raise 'world' | raise Exception('world') | Raise needs an exception class. | Python |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
<ul><li>test<li>world</ul> | <ul><li>test</li><li>world</li></ul> | Close li. | HTML |
cin >> a
cout << a; | cin >> a;
cout << a; | Add semicolon. | C++ |
if (y = 12) {{}} | if (y === 12) {{}} | Use === for equality. | JavaScript |
int[] list = new int[96];
list[96] = 5; | int[] list = new int[96];
if (96 < list.length) list[96] = 5; | Check bounds. | Java |
if foo = 59: | if foo == 59: | Use == for comparison. | Python |
h1 {{ font-size:83px color:#fff; }} | h1 {{ font-size:83px; color:#fff; }} | Add semicolon. | CSS |
val y: Int = 'output' | val y: String = 'output' | Fix type. | Kotlin |
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 |
{{"name":"info",}} | {{"name":"info"}} | Remove trailing comma. | JSON |
object Order {{ def main(args: Array[String]) = println("message") }} | object Order {{ def main(args: Array[String]): Unit = println("message") }} | Add return type Unit. | Scala |
List(95,9,73) | List(95,9,73) | Correct. | Scala |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.