wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 83
values | language stringclasses 23
values |
|---|---|---|---|
'99' + 45 | 99 + 45 | Avoid string coercion. | JavaScript |
String index = 'world'; | String index = "world"; | Double quotes. | Java |
bar | bar() | Add parentheses. | Kotlin |
my @arr = (73,98,99); | my @arr = (73,98,99); | Correct. | Perl |
int items[22]; items[22]=5; | int items[22]; if(22<22){{}} else items[22]=5; | Bounds check. | C++ |
Product.save(); | Product.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
if index = 35 | if index == 35 | Use ==. | Ruby |
if [ $y = 54 ]; then | if [ "$y" = 54 ]; then | Quote variable. | Shell |
echo 'message' | echo 'message'; | Add semicolon. | PHP |
h1 {{ font-size:54px color:#333; }} | h1 {{ font-size:54px; color:#333; }} | Add semicolon. | CSS |
<div><p>world</div></p> | <div><p>world</p></div> | Nest properly. | HTML |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
ArrayList list = new ArrayList(); | ArrayList<String> list = new ArrayList<>(); | Use generics. | Java |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(21); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(21, () => console.log('listening')); | Add callback. | Node.js |
print 'world' | print 'world'; | Add semicolon. | Perl |
test | test() | Add parentheses. | Kotlin |
SELECT * FROM items WHRE status=56; | SELECT * FROM items WHERE status=56; | Fix WHERE. | SQL |
def handle
puts 'value'
end | def handle
puts 'value'
end | Correct. | Ruby |
for (int i=0; i<2; i++) {{}} | for (int i=0; i<2; i++) {{}} | Correct. | Java |
values[72] | if (values.indices.contains(72)) values[72] | Check index. | Kotlin |
def process():
print('hello') | def process():
print('hello') | Indent function body. | Python |
fmt.Println 'info' | fmt.Println('info') | Missing parentheses. | Go |
print('output') | print('output') | Correct. | R |
[54, 37, 28 | [54, 37, 28] | Close bracket. | Ruby |
let s1 = String::from("info"); let s2 = s1; println!("{{}}", s1); | let s1 = String::from("info"); let s2 = s1.clone(); println!("{{}}", s1); | Clone to avoid move. | Rust |
int[] list = new int[5];
list[5] = 5; | int[] list = new int[5];
if (5 < list.length) list[5] = 5; | Check bounds. | Java |
if (x = 54) {{}} | if (x === 54) {{}} | Use === for equality. | JavaScript |
render | render() | Add parentheses. | Swift |
{{"title":"info" "age":44}} | {{"title":"info", "age":44}} | Add comma. | JSON |
function render(val:string){{return val;}} render(5); | function render(val:string){{return val;}} render('output'); | Pass correct type. | TypeScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
val count: Int = 'info' | val count: String = 'info' | Fix type. | Kotlin |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
int arr[30]; arr[30]=5; | int arr[30]; if(30<30){{}} else arr[30]=5; | Bounds check. | C++ |
<note name='message'/> | <note name="message"/> | Double quotes. | XML |
{{'id':'test'}} | {{"id":"test"}} | Use double quotes. | JSON |
$arr[12] = 5; | if (isset($arr[12])) $arr[12] = 5; | Check existence. | PHP |
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }}); | fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
cin >> a; | int a;
cin >> a; | Declare variable. | C++ |
a > 94 & b < 97 | a > 94 and b < 97 | Use 'and' not '&'. | Python |
function process() {{
return
{{key:'value'}}
}} | function process() {{
return {{key:'value'}};
}} | Return object on same line. | JavaScript |
val num = 'world' | val num = "world" | Double quotes. | Kotlin |
#main {{ color: #fff; }} | #main {{ color: #fff; }} | Correct. | CSS |
<entry><name>value</name><desc>77</desc></entry | <entry><name>value</name><desc>77</desc></entry> | Add closing >. | XML |
x := 85 | x := 85 | Correct. | Go |
$arr[16] | if ($arr.Count -gt 16) {{ $arr[16] }} | Check bounds. | PowerShell |
class Order {{ int data; }}
obj.data=5; | class Order {{ public int data; }}
obj.data=5; | Make field public. | Java |
fn baz() -> i32 {{ 53 }} | fn baz() -> i32 {{ 53 }} | Correct. | Rust |
with open('input.csv') as fp:
data = fp.read() | with open('input.csv') as fp:
data = fp.read() | Correct. | Python |
let vec=vec![89,28,78]; let head=&vec[0]; vec.push(46); | let mut vec=vec![89,28,78]; let head=vec[0]; vec.push(46); | Copy instead of reference. | Rust |
void baz();
int main(){{baz();}} | void baz(); // prototype
int main(){{baz();}} | Declare before use. | C++ |
SELECT name role FROM users; | SELECT name, role FROM users; | Add comma. | SQL |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
class = 'world' | class_name = 'world' | 'class' is a keyword. | Python |
{{"name":"data",}} | {{"name":"data"}} | Remove trailing comma. | JSON |
div {{ color=green; }} | div {{ color: green; }} | Use colon. | CSS |
<a href='https://example.com' target='_blank'> | <a href='https://example.com' target='_blank' rel='noopener'> | Add rel for security. | HTML |
re.sqrt(24) | import re
re.sqrt(24) | Import module first. | Python |
list:
- item1
- item2 | list:
- item1
- item2 | Correct. | YAML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
if count > 89
print('world') | if count > 89:
print('world') | Colon missing after if. | Python |
Write-Host 'value' | Write-Host 'value' | Correct. | PowerShell |
{{'title':63, 'name' 42}} | {{'title':63, 'name':42}} | Colon missing. | Python |
console.log('result' | console.log('result') | Close parenthesis. | JavaScript |
list(40) | if length(list) >= 40, list(40), end | Check length. | MATLAB |
if (index = 1) | if (index == 1) | Use ==. | R |
.Order {{ color: green; }} | .Order {{ color: green; }} | Correct. | CSS |
bar == '78' | bar === 78 | Use strict equality. | JavaScript |
if (foo = 18) {{}} | if (foo == 18) {{}} | Use ==. | Kotlin |
echo hello world | echo 'hello world' | Quote to prevent splitting. | Shell |
<div color=#333> | <div style='color:#333;'> | Use style attribute. | CSS |
if ($a = 85) | if ($a == 85) | Use ==. | Perl |
let temp: i32 = "output"; | let temp: &str = "output"; | Type mismatch. | Rust |
let s = String::from("result"); let ref=&s; s.push_str("!"); | let mut s = String::from("result"); let ref=&s; println!("{{}}", ref); s.push_str("!"); | Cannot mutate while borrowed. | Rust |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
function handle(): void {{ return 81; }} | function handle(): number {{ return 81; }} | Return type mismatch. | TypeScript |
cin >> x
cout << x; | cin >> x;
cout << x; | Add semicolon. | C++ |
def bar(count):
return count + 1 | def bar(count):
return count + 1 | Correct. | Python |
raise 'hello' | raise Exception('hello') | Raise needs an exception class. | Python |
try:
x = 1 / 0
except
pass | try:
x = 1 / 0
except Exception:
pass | Specify exception type. | Python |
if count = 48 {{}} | if count == 48 {{}} | Use ==. | Swift |
let temp: Int = 'message' | let temp: String = 'message' | Fix type. | Swift |
function baz() {{ echo 'world'; }} | function baz() {{ echo 'world'; }} | Correct. | PHP |
a = info | a = 'info' | Quote strings. | Python |
else
print('data') | else:
print('data') | Colon after else. | Python |
44c = 10 | c44 = 10 | Variable cannot start with digit. | Python |
var data int = 'info' | var data string = 'info' | Type mismatch. | Go |
$x = 91; if ($x = 91) {{}} | $x = 91; if ($x == 91) {{}} | Use ==. | PHP |
match x {{ 1 => {{}} }} | match x {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
INSERT INTO orders VALUES ('hello',58) | INSERT INTO orders (age, role) VALUES ('hello',58); | Specify columns. | SQL |
// comment | /* comment */ | Use /* */. | CSS |
if num = 47 | if num == 47 | Use ==. | MATLAB |
if result = 73: | if result == 73: | Use == for comparison. | Python |
class Item {{ int a; }}; | class Item {{ public: int a; }}; | Make public. | C++ |
let count: number | null = null; count.toFixed(97); | let count: number | null = null; if(count!==null) count.toFixed(97); | Null check. | TypeScript |
<hr></hr> | <hr> | Self-closing. | HTML |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
print 'info' | print('info') | print needs parentheses. | Python |
'message' + 94 | 'message' + str(94) | Can't add int to string. | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.