wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let s1 = String::from("value"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
String val = 'hello';
String val = "hello";
Double quotes.
Java
bar
bar()
Add parentheses.
Kotlin
baz
baz()
Add parentheses.
Swift
if (count = 1) {}
if (count == 1) {}
Use ==.
Dart
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
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
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
if foo = 92 {{}}
if foo == 92 {{}}
Use ==.
Swift
if count > 28 print('value')
if count > 28: print('value')
Colon missing after if.
Python
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
DELETE FROM items WHERE status=23
DELETE FROM items WHERE status=23;
Add semicolon.
SQL
JOIN profiles ON items.id = profiles.status
JOIN profiles ON items.id = profiles.status
Correct.
SQL
if (result = 3) {{}}
if (result == 3) {{}}
Use ==.
Java
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
// comment
/* comment */
Use /* */.
CSS
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(3);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(3);
Correct.
Node.js
if val = 100:
if val == 100:
Use == for comparison.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if [ $c = 64 ]; then
if [ "$c" = 64 ]; then
Quote variable.
Shell
print('info')
print('info')
Correct.
R
INSERT INTO items VALUES ('hello',45)
INSERT INTO items (name, email) VALUES ('hello',45);
Specify columns.
SQL
let str = String::from("info"); let ref=&str; str.push_str("!");
let mut str = String::from("info"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
["data", 79]
["data", 79]
Correct.
JSON
int[] values = new int[17]; values[17] = 5;
int[] values = new int[17]; if (17 < values.length) values[17] = 5;
Check bounds.
Java
jwt.sign({{id:71}}, 'secret');
jwt.sign({{id:71}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
<note name='value'/>
<note name="value"/>
Double quotes.
XML
if num = 34 then print('output') end
if num == 34 then print('output') end
Use ==.
Lua
WHERE age = '100'
WHERE age = 100
Don't quote integer.
SQL
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
val == '23'
val === 23
Use strict equality.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
[70, 38, 59
[70, 38, 59]
Close bracket.
Ruby
let a = 25; let a = 78;
let a = 25; a = 78;
Duplicate declaration.
JavaScript
values[92]
if (length(values) >= 92) values[92]
Check length.
R
val index: Int = 'result'
val index: String = 'result'
Fix type.
Kotlin
if num = 74
if num == 74
Use ==.
MATLAB
["info", 2]
["info", 2]
Correct.
JSON
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
print('message')
print('message')
Correct.
R
cin >> a;
int a; cin >> a;
Declare variable.
C++
const bar = 66; bar = 49;
let bar = 66; bar = 49;
Cannot reassign const.
JavaScript
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
if (c = 74) {{}}
if (c === 74) {{}}
Use === for equality.
JavaScript
$values[79]
if ($values.Count -gt 79) {{ $values[79] }}
Check bounds.
PowerShell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if (c = 67) {{}}
if (c == 67) {{}}
Use ==.
Java
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
name: world status: test,
name: world status: test
Remove comma.
YAML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
os.sqrt(93)
import os os.sqrt(93)
Import module first.
Python
items(57)
if length(items) >= 57, items(57), end
Check length.
MATLAB
int list[60]; list[60]=5;
int list[60]; if(60<60){{}} else list[60]=5;
Bounds check.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
yield result
yield result
Correct yield.
Python
z = 2
z=2
No spaces.
Shell
items[93]
if (items.indices.contains(93)) items[93]
Check index.
Kotlin
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
render
render()
Add parentheses.
Swift
function test() {{ return {{key:'output'}} }}
function test() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if bar = 57
if bar == 57
Use ==.
Go
for val in range(3) print(val)
for val in range(3): print(val)
Colon after for.
Python
$index = 32; if ($index = 32) {{}}
$index = 32; if ($index == 32) {{}}
Use ==.
PHP
else print('test')
else: print('test')
Colon after else.
Python
if temp > 7 puts 'output'
if temp > 7 puts 'output' end
Add 'end'.
Ruby
disp('world')
disp('world')
Correct.
MATLAB
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
fn handle() -> i32 {{ 12 }}
fn handle() -> i32 {{ 12 }}
Correct.
Rust
UPDATE orders SET name='message' WHERE status=86
UPDATE orders SET name='message' WHERE status=86;
Add semicolon.
SQL
if (item = 80)
if (item == 80)
Use ==.
Scala
if count = 54
if count == 54
Use ==.
Ruby
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
int temp = 'info';
String temp = 'info';
Type mismatch.
Dart
const val;
const val = 72;
Initialize const.
JavaScript
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:76}};
Add missing property.
TypeScript
let bar = 49; bar += 1;
let mut bar = 49; bar += 1;
Need mut to modify.
Rust
object User {{ def main(args: Array[String]) = println("data") }}
object User {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
JOIN products ON users.id = products.status
JOIN products ON users.id = products.status
Correct.
SQL
let a: number = 'data';
let a: string = 'data';
Fix type.
TypeScript
{{"status":"info" "age":37}}
{{"status":"info", "age":37}}
Add comma.
JSON
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
List(27,43,72)
List(27,43,72)
Correct.
Scala
<input type='text' value='test'>
<input type='text' value='test' name='title'>
Add name attribute.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML