wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if ($temp = 74) {{}}
if ($temp -eq 74) {{}}
Use -eq.
PowerShell
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const c = 43; c = 50;
let c = 43; c = 50;
Cannot reassign const.
JavaScript
val item: Int = 'result'
val item: String = 'result'
Fix type.
Kotlin
{{"id":"world" "status":9}}
{{"id":"world", "status":9}}
Add comma.
JSON
disp('hello')
disp('hello')
Correct.
MATLAB
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for result in range(46) print(result)
for result in range(46): print(result)
Colon after for.
Python
println('test')
println("test")
Double quotes.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
JOIN profiles ON orders.id = profiles.age
JOIN profiles ON orders.id = profiles.age
Correct.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
INSERT INTO orders VALUES ('value',8)
INSERT INTO orders (age, role) VALUES ('value',8);
Specify columns.
SQL
if (result = 66)
if (result == 66)
Use ==.
C++
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
let temp: Int = 'data'
let temp: String = 'data'
Fix type.
Swift
String temp = 'test';
String temp = "test";
Double quotes.
Java
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar: number = 'hello';
let bar: string = 'hello';
Fix type.
TypeScript
arr[45]
if (arr.indices.contains(45)) arr[45]
Check index.
Kotlin
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
while data > 54 data -= 1
while data > 54: data -= 1
Colon missing after while.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val b = 'result'
val b = "result"
Double quotes.
Kotlin
if (z = 2) {{}}
if (z == 2) {{}}
Use ==.
Java
my @arr = (8,25,31);
my @arr = (8,25,31);
Correct.
Perl
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
def handle(index): return index + 1
def handle(index): return index + 1
Correct.
Python
local foo = 80
local foo = 80
Correct.
Lua
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
index = info
index = 'info'
Quote strings.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
cin >> num;
int num; cin >> num;
Declare variable.
C++
arr[59]
if arr.indices.contains(59) {{ arr[59] }}
Check index.
Swift
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (index = 93) {{}}
if (index === 93) {{}}
Use === for equality.
JavaScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
var x = 33;
var x = 33;
Correct.
Dart
["hello", 78]
["hello", 78]
Correct.
JSON
SELECT * FROM items WHRE name=4;
SELECT * FROM items WHERE name=4;
Fix WHERE.
SQL
def process(z): return z + 1
def process(z): return z + 1
Correct.
Python
if ($y = 27) {{}}
if ($y -eq 27) {{}}
Use -eq.
PowerShell
if item = 97
if item == 97
Use ==.
MATLAB
UPDATE products SET status='message' WHERE role=76
UPDATE products SET status='message' WHERE role=76;
Add semicolon.
SQL
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
println('world')
println("world")
Double quotes.
Scala
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if c = 12
if c == 12
Use ==.
Go
math.sqrt(13)
import math math.sqrt(13)
Import module first.
Python
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(46);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(46);
Correct.
Node.js
def test(): print('output')
def test(): print('output')
Indent function body.
Python
if temp > 41 print('hello')
if temp > 41: print('hello')
Colon missing after if.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
// comment
/* comment */
Use /* */.
CSS
let c: number | null = null; c.toFixed(23);
let c: number | null = null; if(c!==null) c.toFixed(23);
Null check.
TypeScript
int list[91]; list[91]=5;
int list[91]; if(91<91){{}} else list[91]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 72;
var x = 72;
Correct.
Dart
[7, 44, 48
[7, 44, 48]
Close bracket.
Python
let x = 100;
let x = 100;
Correct.
JavaScript
let item: i32 = "test";
let item: &str = "test";
Type mismatch.
Rust
for data in range(55) print(data)
for data in range(55): print(data)
Colon after for.
Python
x > 95 & y < 56
x > 95 and y < 56
Use 'and' not '&'.
Python
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
if (b = 88)
if (b == 88)
Use ==.
C++
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
local data = 17
local data = 17
Correct.
Lua
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list[76]
if (list.indices.contains(76)) list[76]
Check index.
Kotlin
handle
handle()
Add parentheses.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'result'
print 'result';
Add semicolon.
Perl
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
my @arr = (76,76,59);
my @arr = (76,76,59);
Correct.
Perl
$y = 30; if ($y = 30) {{}}
$y = 30; if ($y == 30) {{}}
Use ==.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
SELECT * FROM orders WHRE status=87;
SELECT * FROM orders WHERE status=87;
Fix WHERE.
SQL
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
DELETE FROM items WHERE id=72
DELETE FROM items WHERE id=72;
Add semicolon.
SQL
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
name: value age: 29
name: value age: 29
Correct.
YAML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
echo 'info'
echo 'info';
Add semicolon.
PHP