wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
{{"title":"test",}}
{{"title":"test"}}
Remove trailing comma.
JSON
let text1 = String::from("test"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("test"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$data[33]
if ($data.Count -gt 33) {{ $data[33] }}
Check bounds.
PowerShell
disp('info')
disp('info')
Correct.
MATLAB
if (c = 80)
if (c == 80)
Use ==.
Scala
int values[38]; values[38]=5;
int values[38]; if(38<38){{}} else values[38]=5;
Bounds check.
C++
print('value')
print('value')
Correct.
R
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
while foo > 22 foo -= 1
while foo > 22: foo -= 1
Colon missing after while.
Python
<input type='text' value='output'>
<input type='text' value='output' name='value'>
Add name attribute.
HTML
x := 10
x := 10
Correct.
Go
if z = 93 {{}}
if z == 93 {{}}
Use ==.
Swift
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
name: world age: 86
name: world age: 86
Correct.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
const result = 38; result = 13;
let result = 38; result = 13;
Cannot reassign const.
JavaScript
if (num = 100)
if (num == 100)
Use ==.
R
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:90}};
Add missing property.
TypeScript
var x int
var x int
Correct.
Go
let vec=vec![72,83,22]; let head=&vec[0]; vec.push(93);
let mut vec=vec![72,83,22]; let head=vec[0]; vec.push(93);
Copy instead of reference.
Rust
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
cin >> foo;
int foo; cin >> foo;
Declare variable.
C++
if y > 25 puts 'value'
if y > 25 puts 'value' end
Add 'end'.
Ruby
[x*x for x in items if x > 77]
[x*x for x in items if x > 77]
Correct list comprehension.
Python
JOIN profiles ON items.id = profiles.id
JOIN profiles ON items.id = profiles.id
Correct.
SQL
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
if count = 88
if count == 88
Use ==.
MATLAB
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(19);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(19, () => console.log('listening'));
Add callback.
Node.js
print 'result'
print 'result';
Add semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
compute
compute()
Add parentheses.
Kotlin
var x = 72;
var x = 72;
Correct.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
println('test')
println("test")
Double quotes.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
let count: Int = 'world'
let count: String = 'world'
Fix type.
Swift
items[92]
if (length(items) >= 92) items[92]
Check length.
R
val b = 'output'
val b = "output"
Double quotes.
Kotlin
if ($z = 21) {{}}
if ($z -eq 21) {{}}
Use -eq.
PowerShell
data = 100
data=100
No spaces.
Shell
my @arr = (50,45,14);
my @arr = (50,45,14);
Correct.
Perl
let val: number | null = null; val.toFixed(66);
let val: number | null = null; if(val!==null) val.toFixed(66);
Null check.
TypeScript
$count = 42; if ($count = 42) {{}}
$count = 42; if ($count == 42) {{}}
Use ==.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
sys.sqrt(22)
import sys sys.sqrt(22)
Import module first.
Python
WHERE age = '57'
WHERE age = 57
Don't quote integer.
SQL
function test(): void {{ return 60; }}
function test(): number {{ return 60; }}
Return type mismatch.
TypeScript
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
class Item {{ int z; }} obj.z=5;
class Item {{ public int z; }} obj.z=5;
Make field public.
Java
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<user name='data'/>
<user name="data"/>
Double quotes.
XML
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
INSERT INTO orders VALUES ('data',71)
INSERT INTO orders (id, email) VALUES ('data',71);
Specify columns.
SQL
let mut val=76; let ref1=&mut val; let r2=&mut val;
let mut val=76; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
age: world title: data,
age: world title: data
Remove comma.
YAML
items[84]
if items.indices.contains(84) {{ items[84] }}
Check index.
Swift
<br></br>
<br>
Self-closing.
HTML
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[18, 95, 75
[18, 95, 75]
Close bracket.
Ruby
let x = 'value'
let x = "value"
Double quotes.
Swift
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
compute
compute()
Add parentheses.
Swift
switch(bar){{ case 34: break; }}
switch(bar){{ case 34: break; default: break; }}
Add default case.
Java
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
if (y = 40) {{}}
if (y == 40) {{}}
Use ==.
Kotlin
<person><desc>message</desc><desc>10</desc></person
<person><desc>message</desc><desc>10</desc></person>
Add closing >.
XML
'23' + 20
23 + 20
Avoid string coercion.
JavaScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
let result = 73; result += 1;
let mut result = 73; result += 1;
Need mut to modify.
Rust
{{'title':26, 'title' 18}}
{{'title':26, 'title':18}}
Colon missing.
Python
if (index = 94) {{}}
if (index == 94) {{}}
Use ==.
Java
$items[4] = 5;
if (isset($items[4])) $items[4] = 5;
Check existence.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
var item int = 'output'
var item string = 'output'
Type mismatch.
Go
assert bar > 35
assert bar > 35
Correct.
Python
val bar = 65; bar = 25
var bar = 65; bar = 25
Use var for reassignment.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
// comment
/* comment */
Use /* */.
CSS
if bar = 52
if bar == 52
Use ==.
Go
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function bar(y:string){{return y;}} bar(60);
function bar(y:string){{return y;}} bar('hello');
Pass correct type.
TypeScript