DEV Community

Cover image for Let's develop a QR Code Generator, part II: sequencing data

Let's develop a QR Code Generator, part II: sequencing data

Massimo Artizzu on July 10, 2021

In the first part we've seen the basic concepts of QR codes. Now let's actively do something to generate one. Let's suppose we want to create a QR ...
Collapse
 
pauljherring profile image
PJH
 const bitsIndex = version > 26 ? 2 : version > 9 ? 1 : 0;
Enter fullscreen mode Exit fullscreen mode

That's horrible, and has a code smell of "I can write cute code" while making it clear that the author likes writing unmaintainable code.

Collapse
 
juan_fransanchezgarcia_ profile image
Juan Fran Sanchez Garcia • Edited

I’m speaking up because I wouldn’t want to receive this kind of comment. Comments like this seem more about showing off than offering constructive feedback in a humble way. Let's keep the focus on learning and mutual support, especially when dealing with something as nuanced as QR code generation.

Collapse
 
maxart2501 profile image
Massimo Artizzu • Edited

I beg to differ.

I agree that's not pretty and could be refactored in a slightly more readable way, but you're missing the big picture. The whole algorithm contains some quite advanced mathematics, and for the sole task to dive into this a double ternary - that I've already explained before - is basically the least of your problems. Speaks for itself the fact that in almost 3 years you're the only one that complained about this.

On the other hand, I must underline how your way of giving feedback is, without a doubt, horrible.

Collapse
 
latestversion profile image
latestversion

I was wondering a bit about the result from the getByteData function. The "hand code" section result differs slightly from the final output. It seems to be either the length bits or the first character that differs, IIUC.

"hand code": 65, 118, 135, 71, 71 ...
getByteData: 65, 166, 135, 71, 71 ...

Maybe I missed some difference. I get 65, 118 ... so I hope that's correct :)

Collapse
 
autj profile image
AutJ

type error in the last code block
Uint8Array(26) -> Uint8Array(28)

Collapse
 
maxart2501 profile image
Massimo Artizzu

Good catch, thanks 👍

Collapse
 
lotfijb profile image
Lotfi Jebali • Edited

Nice article and thanks for sharing with the community
Excited to read more of your writings

Collapse
 
prithulb profile image
Prithul Biswas

i didn't get the encoding. :(
h = 104 why make 65 ? why we don't cenvert [104 116 116 112 115 58 47 47 119 119 119 46 113 114 99 111 100 101
46 99 111 109 47] this array into binary..? :/