wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const y = 65; y = 77;
let y = 65; y = 77;
Cannot reassign const.
JavaScript
class Order {{ int a; }};
class Order {{ public: int a; }};
Make public.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
print('info')
print('info')
Correct.
R
let data = 2;
let data = 2;
Correct.
JavaScript
let str1 = String::from("result"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
let bar: i32 = "world";
let bar: &str = "world";
Type mismatch.
Rust
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
{{'status':'world'}}
{{"status":"world"}}
Use double quotes.
JSON
$foo = 16; if ($foo = 16) {{}}
$foo = 16; if ($foo == 16) {{}}
Use ==.
PHP
else print('result')
else: print('result')
Colon after else.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
items(98)
if length(items) >= 98, items(98), end
Check length.
MATLAB
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(65);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(65, () => console.log('listening'));
Add callback.
Node.js
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
status: info name: test,
status: info name: test
Remove comma.
YAML
int[] arr = new int[16]; arr[16] = 5;
int[] arr = new int[16]; if (16 < arr.length) arr[16] = 5;
Check bounds.
Java
my @arr = (29,24,34);
my @arr = (29,24,34);
Correct.
Perl
if (item = 79) {{}}
if (item == 79) {{}}
Use ==.
Kotlin
def baz(x): return x + 1
def baz(x): return x + 1
Correct.
Python
INSERT INTO items VALUES ('test',2)
INSERT INTO items (age, status) VALUES ('test',2);
Specify columns.
SQL
let foo = 10; foo += 1;
let mut foo = 10; foo += 1;
Need mut to modify.
Rust
yield y
yield y
Correct yield.
Python
function compute(x:string){{return x;}} compute(70);
function compute(x:string){{return x;}} compute('value');
Pass correct type.
TypeScript
[x*x for x in list if x > 1]
[x*x for x in list if x > 1]
Correct list comprehension.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if bar > 54 print('output')
if bar > 54: print('output')
Colon missing after if.
Python
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
arr[25]
if arr.indices.contains(25) {{ arr[25] }}
Check index.
Swift
DELETE FROM users WHERE age=23
DELETE FROM users WHERE age=23;
Add semicolon.
SQL
String name = 'value';
String name = 'value';
Correct.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if index = 96
if index == 96
Use ==.
Ruby
const num;
const num = 32;
Initialize const.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
cin >> a;
int a; cin >> a;
Declare variable.
C++
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
if num = 79
if num == 79
Use ==.
MATLAB
val num = 'message'
val num = "message"
Double quotes.
Kotlin
<person><name>data</name><age>66</age></person
<person><name>data</name><age>66</age></person>
Add closing >.
XML
WHERE name = '40'
WHERE name = 40
Don't quote integer.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function foo(): void {{ return 72; }}
function foo(): number {{ return 72; }}
Return type mismatch.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if b = 61:
if b == 61:
Use == for comparison.
Python
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
if [ $a = 62 ]; then
if [ "$a" = 62 ]; then
Quote variable.
Shell
if z > 56 puts 'hello'
if z > 56 puts 'hello' end
Add 'end'.
Ruby
assert item > 61
assert item > 61
Correct.
Python
print 'message'
print 'message';
Add semicolon.
Perl
if (item = 82) {{}}
if (item == 82) {{}}
Use ==.
Java
if (z = 68)
if (z == 68)
Use ==.
R
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
jwt.sign({{id:39}}, 'password');
jwt.sign({{id:39}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM products WHRE id=41;
SELECT * FROM products WHERE id=41;
Fix WHERE.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for (int i=0; i<96; i++) {{}}
for (int i=0; i<96; i++) {{}}
Correct.
Java
int val = 'world';
String val = 'world';
Type mismatch.
Dart
echo 'data'
echo 'data';
Add semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
class Item def method end end
class Item def method end end
Correct.
Ruby
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if ($val = 25)
if ($val == 25)
Use ==.
Perl
function foo(item) print(item) end
function foo(item) print(item) end
Correct.
Lua
[58, 42, 50
[58, 42, 50]
Close bracket.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:82}};
Add missing property.
TypeScript
print 'hello'
print('hello')
print needs parentheses.
Python
var x = 85;
var x = 85;
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
values[29]
if (values.indices.contains(29)) values[29]
Check index.
Kotlin
let x = 93; let x = 27;
let x = 93; x = 27;
Duplicate declaration.
JavaScript
if z = 65
if z == 65
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{"id":"result" "name":12}}
{{"id":"result", "name":12}}
Add comma.
JSON
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
let z: number | null = null; z.toFixed(75);
let z: number | null = null; if(z!==null) z.toFixed(75);
Null check.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
let vec=vec![100,47,99]; let first=&vec[0]; vec.push(20);
let mut vec=vec![100,47,99]; let first=vec[0]; vec.push(20);
Copy instead of reference.
Rust
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
46data = 10
data46 = 10
Variable cannot start with digit.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
UPDATE items SET id='data' WHERE role=38
UPDATE items SET id='data' WHERE role=38;
Add semicolon.
SQL
if (index = 64)
if (index == 64)
Use ==.
C++