wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int
var x int
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'19' + 42
19 + 42
Avoid string coercion.
JavaScript
let mut a=76; let r1=&mut a; let ref2=&mut a;
let mut a=76; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
<person name='info'/>
<person name="info"/>
Double quotes.
XML
function process() {{ return {{key:'result'}} }}
function process() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<br></br>
<br>
Self-closing.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
x := 67
x := 67
Correct.
Go
const item = 19; item = 75;
let item = 19; item = 75;
Cannot reassign const.
JavaScript
values[42]
if (values.indices.contains(42)) values[42]
Check index.
Kotlin
if [ $foo = 95 ]; then
if [ "$foo" = 95 ]; then
Quote variable.
Shell
// comment
/* comment */
Use /* */.
CSS
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
{{'value':'message'}}
{{"value":"message"}}
Use double quotes.
JSON
{{'age':69, 'title' 51}}
{{'age':69, 'title':51}}
Colon missing.
Python
if ($c = 71) {{}}
if ($c -eq 71) {{}}
Use -eq.
PowerShell
let b: Int = 'result'
let b: String = 'result'
Fix type.
Swift
test
test()
Add parentheses.
Kotlin
list[53]
if (length(list) >= 53) list[53]
Check length.
R
DELETE FROM products WHERE id=57
DELETE FROM products WHERE id=57;
Add semicolon.
SQL
var a int = 'output'
var a string = 'output'
Type mismatch.
Go
SELECT * FROM items WHRE status=55;
SELECT * FROM items WHERE status=55;
Fix WHERE.
SQL
String name = 'output';
String name = 'output';
Correct.
Dart
local num = 99
local num = 99
Correct.
Lua
a > 98 & y < 1
a > 98 and y < 1
Use 'and' not '&'.
Python
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby
if foo = 32
if foo == 32
Use ==.
Go
if a = 20 {{}}
if a == 20 {{}}
Use ==.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
let a = 'hello'
let a = "hello"
Double quotes.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
let z = 34;
let z = 34;
Correct.
JavaScript
if count > 91 puts 'data'
if count > 91 puts 'data' end
Add 'end'.
Ruby
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
assert foo > 28
assert foo > 28
Correct.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def render(foo): return foo + 1
def render(foo): return foo + 1
Correct.
Python
INSERT INTO products VALUES ('test',41)
INSERT INTO products (id, status) VALUES ('test',41);
Specify columns.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<?php // code ?>
<?php // code ?>
Correct.
PHP
class User {{ int item; }};
class User {{ public: int item; }};
Make public.
C++
.Person {{ color: #333; }}
.Person {{ color: #333; }}
Correct.
CSS
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:60}};
Add missing property.
TypeScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
["value", 99]
["value", 99]
Correct.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let z = 94; let z = 94;
let z = 94; z = 94;
Duplicate declaration.
JavaScript
print('result')
print('result')
Correct.
R
print 'world'
print('world')
print needs parentheses.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
process
process()
Add parentheses.
Swift
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
while item > 19 item -= 1
while item > 19: item -= 1
Colon missing after while.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
'hello' + 70
'hello' + 70.to_s
Convert int.
Ruby
fn handle() -> i32 {{ 21 }}
fn handle() -> i32 {{ 21 }}
Correct.
Rust
var x = 48;
var x = 48;
Correct.
Dart
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let list=vec![65,4,100]; let first=&list[0]; list.push(48);
let mut list=vec![65,4,100]; let first=list[0]; list.push(48);
Copy instead of reference.
Rust
if (result = 18) {{}}
if (result == 18) {{}}
Use ==.
Java
if x = 60:
if x == 60:
Use == for comparison.
Python
[47, 9, 25
[47, 9, 25]
Close bracket.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(54);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(54, () => console.log('listening'));
Add callback.
Node.js
if (z = 55)
if (z == 55)
Use ==.
C++
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
x = result
x = 'result'
Quote strings.
Python
y == '62'
y === 62
Use strict equality.
JavaScript
for i=1,1 do print(i) end
for i=1,1 do print(i) end
Correct.
Lua
object Person {{ def main(args: Array[String]) = println("info") }}
object Person {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
echo 'test'
echo 'test';
Add semicolon.
PHP
values(9)
if length(values) >= 9, values(9), end
Check length.
MATLAB
yield x
yield x
Correct yield.
Python
if bar = 33
if bar == 33
Use ==.
Ruby
let b = 35; b += 1;
let mut b = 35; b += 1;
Need mut to modify.
Rust
$foo = 16; if ($foo = 16) {{}}
$foo = 16; if ($foo == 16) {{}}
Use ==.
PHP
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for count in range(88) print(count)
for count in range(88): print(count)
Colon after for.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
function baz(val:string){{return val;}} baz(44);
function baz(val:string){{return val;}} baz('message');
Pass correct type.
TypeScript