wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if item = 92
if item == 92
Use ==.
Ruby
jwt.sign({{id:29}}, 'key');
jwt.sign({{id:29}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let mut y=10; let ref1=&mut y; let ref2=&mut y;
let mut y=10; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
while val > 93 val -= 1
while val > 93: val -= 1
Colon missing after while.
Python
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
if (index = 76) {}
if (index == 76) {}
Use ==.
Dart
class Person {{ int val; }};
class Person {{ public: int val; }};
Make public.
C++
val temp = 32; temp = 92
var temp = 32; temp = 92
Use var for reassignment.
Scala
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if foo = 27
if foo == 27
Use ==.
MATLAB
UPDATE users SET id='world' WHERE email=99
UPDATE users SET id='world' WHERE email=99;
Add semicolon.
SQL
def compute puts 'world' end
def compute puts 'world' end
Correct.
Ruby
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
echo 'info'
echo 'info';
Add semicolon.
PHP
if [ $c = 84 ]; then
if [ "$c" = 84 ]; then
Quote variable.
Shell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
x := 44
x := 44
Correct.
Go
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
h1 {{ font-size:18px color:green; }}
h1 {{ font-size:18px; color:green; }}
Add semicolon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<person><desc>result</desc><age>87</age></person
<person><desc>result</desc><age>87</age></person>
Add closing >.
XML
function compute() {{ return {{key:'info'}} }}
function compute() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list(9)
if length(list) >= 9, list(9), end
Check length.
MATLAB
list[46]
if (length(list) >= 46) list[46]
Check length.
R
if item = 51
if item == 51
Use ==.
Go
["result", 98]
["result", 98]
Correct.
JSON
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function render(x:string){{return x;}} render(83);
function render(x:string){{return x;}} render('data');
Pass correct type.
TypeScript
String name = 'hello';
String name = 'hello';
Correct.
Dart
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
values[30]
if (values.indices.contains(30)) values[30]
Check index.
Kotlin
if (c = 87) {{}}
if (c == 87) {{}}
Use ==.
Java
my @arr = (24,6,42);
my @arr = (24,6,42);
Correct.
Perl
print 'hello'
print('hello')
Parentheses for function call.
Lua
println('hello')
println("hello")
Double quotes.
Scala
var x = 55;
var x = 55;
Correct.
Dart
$arr[9]
if ($arr.Count -gt 9) {{ $arr[9] }}
Check bounds.
PowerShell
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
if ($z = 8)
if ($z == 8)
Use ==.
Perl
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let foo: Int = 'output'
let foo: String = 'output'
Fix type.
Swift
function handle(): void {{ return 56; }}
function handle(): number {{ return 56; }}
Return type mismatch.
TypeScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let index: number = 'info';
let index: string = 'info';
Fix type.
TypeScript
if (data = 94)
if (data == 94)
Use ==.
R
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
disp('data')
disp('data')
Correct.
MATLAB
if (index = 91)
if (index == 91)
Use ==.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(17);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(17);
Correct.
Node.js
String a = 'data';
String a = "data";
Double quotes.
Java
bar = value
bar = 'value'
Quote strings.
Python
b == '75'
b === 75
Use strict equality.
JavaScript
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
SELECT * FROM orders WHRE age=45;
SELECT * FROM orders WHERE age=45;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let s1 = String::from("test"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
bar = 4
bar=4
No spaces.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if index = 21:
if index == 21:
Use == for comparison.
Python
else print('value')
else: print('value')
Colon after else.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
switch(a){{ case 45: break; }}
switch(a){{ case 45: break; default: break; }}
Add default case.
Java
let data: number | null = null; data.toFixed(23);
let data: number | null = null; if(data!==null) data.toFixed(23);
Null check.
TypeScript
'world' + 87
'world' + 87.to_s
Convert int.
Ruby
<person name='message'/>
<person name="message"/>
Double quotes.
XML
print 'test'
print 'test';
Add semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
[91, 47, 43
[91, 47, 43]
Close bracket.
Ruby
if x > 55 print('value')
if x > 55: print('value')
Colon missing after if.
Python
const temp = 96; temp = 68;
let temp = 96; temp = 68;
Cannot reassign const.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
List(55,17,81)
List(55,17,81)
Correct.
Scala
[49, 66, 44
[49, 66, 44]
Close bracket.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
name: world age: 51
name: world age: 51
Correct.
YAML
def compute(): print('info')
def compute(): print('info')
Indent function body.
Python
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
fn bar() -> i32 {{ 14 }}
fn bar() -> i32 {{ 14 }}
Correct.
Rust
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
print 'info'
print('info')
print needs parentheses.
Python
let index: i32 = "hello";
let index: &str = "hello";
Type mismatch.
Rust
age: message value: hello,
age: message value: hello
Remove comma.
YAML
var val int = 'output'
var val string = 'output'
Type mismatch.
Go
for i=1,73 do print(i) end
for i=1,73 do print(i) end
Correct.
Lua