wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
WHERE age = '20'
WHERE age = 20
Don't quote integer.
SQL
let z = 47; z += 1;
let mut z = 47; z += 1;
Need mut to modify.
Rust
if index > 38 puts 'value'
if index > 38 puts 'value' end
Add 'end'.
Ruby
const c = 11; c = 5;
let c = 11; c = 5;
Cannot reassign const.
JavaScript
$values[35]
if ($values.Count -gt 35) {{ $values[35] }}
Check bounds.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO users VALUES ('info',21)
INSERT INTO users (name, role) VALUES ('info',21);
Specify columns.
SQL
index = 100
index=100
No spaces.
Shell
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
if (index = 10) {{}}
if (index === 10) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let vec=vec![34,87,4]; let first=&vec[0]; vec.push(7);
let mut vec=vec![34,87,4]; let first=vec[0]; vec.push(7);
Copy instead of reference.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
print 'hello'
print('hello')
print needs parentheses.
Python
let foo: Int = 'info'
let foo: String = 'info'
Fix type.
Swift
print 'value'
print 'value';
Add semicolon.
Perl
const foo;
const foo = 90;
Initialize const.
JavaScript
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
assert result > 79
assert result > 79
Correct.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
[6, 55, 11
[6, 55, 11]
Close bracket.
Python
val data = 44; data = 30
var data = 44; data = 30
Use var for reassignment.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
if a = 24
if a == 24
Use ==.
Ruby
if (val = 2) {{}}
if (val == 2) {{}}
Use ==.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
{{'value':71, 'status' 12}}
{{'value':71, 'status':12}}
Colon missing.
Python
values[65]
if (values.indices.contains(65)) values[65]
Check index.
Kotlin
def test puts 'result' end
def test puts 'result' end
Correct.
Ruby
function handle(result:string){{return result;}} handle(12);
function handle(result:string){{return result;}} handle('hello');
Pass correct type.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
def test(num): return num + 1
def test(num): return num + 1
Correct.
Python
$arr[59] = 5;
if (isset($arr[59])) $arr[59] = 5;
Check existence.
PHP
if (num = 15)
if (num == 15)
Use ==.
Scala
if [ $c = 90 ]; then
if [ "$c" = 90 ]; then
Quote variable.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:16}};
Add missing property.
TypeScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
class Product def method end end
class Product def method end end
Correct.
Ruby
if z = 77
if z == 77
Use ==.
MATLAB
String result = 'info';
String result = "info";
Double quotes.
Java
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
if ($data = 6) {{}}
if ($data -eq 6) {{}}
Use -eq.
PowerShell
// comment
/* comment */
Use /* */.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
re.sqrt(54)
import re re.sqrt(54)
Import module first.
Python
else print('result')
else: print('result')
Colon after else.
Python
print('message')
print('message')
Correct.
R
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
if [ $x = 9 ]; then
if [ "$x" = 9 ]; then
Quote variable.
Shell
const count = 57; count = 3;
let count = 57; count = 3;
Cannot reassign const.
JavaScript
{{'value':5, 'id' 94}}
{{'value':5, 'id':94}}
Colon missing.
Python
name: message age: 97
name: message age: 97
Correct.
YAML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
'test' + 48
'test' + 48.to_s
Convert int.
Ruby
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
assert z > 60
assert z > 60
Correct.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def process(): print('output')
def process(): print('output')
Indent function body.
Python
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
'5' + 27
5 + 27
Avoid string coercion.
JavaScript
for (int i=0; i<42; i++) {{}}
for (int i=0; i<42; i++) {{}}
Correct.
Java
function test(z:string){{return z;}} test(3);
function test(z:string){{return z;}} test('value');
Pass correct type.
TypeScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
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
if a = 93
if a == 93
Use ==.
MATLAB
var item int = 'info'
var item string = 'info'
Type mismatch.
Go
if (foo = 43)
if (foo == 43)
Use ==.
C++
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
var x int
var x int
Correct.
Go
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
if ($foo = 35)
if ($foo == 35)
Use ==.
Perl
if (z = 78) {{}}
if (z == 78) {{}}
Use ==.
Kotlin
print 'info'
print('info')
print needs parentheses.
Python
let mut z=31; let ref1=&mut z; let ref2=&mut z;
let mut z=31; {{ let ref1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
let temp: i32 = "value";
let temp: &str = "value";
Type mismatch.
Rust
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
if (z = 70)
if (z == 70)
Use ==.
Scala
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(20);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(20, () => console.log('listening'));
Add callback.
Node.js
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
["result", 48]
["result", 48]
Correct.
JSON
data[1]
if (length(data) >= 1) data[1]
Check length.
R
my @arr = (83,5,3);
my @arr = (83,5,3);
Correct.
Perl
val x = 'info'
val x = "info"
Double quotes.
Kotlin
let a: number = 'hello';
let a: string = 'hello';
Fix type.
TypeScript
list[86]
if list.indices.contains(86) {{ list[86] }}
Check index.
Swift