Coding Blocks - Data Structures – Primitives
Episode Date: November 19, 2018We begin our journey into data structures by taking a deep dive into primitives while Allen makes Michael blush and Joe crashes his browser....
Transcript
Discussion (0)
You're listening to Coding Blocks, episode 94.
Subscribe to us and leave us a review on iTunes, Stitcher, and more using your favorite podcast app.
And you can head to CodingBlocks.net and find show notes, examples, discussions, and a lot of other things.
That was way more animated than I expected.
Send your feedback, questions, and rants to comments at CodingBlocks.net.
Follow us on Twitter at CodingBlocks or head to www.codyblocks.net and find
all our social links there at the top of the page.
With that,
I'm Alan Underwood.
I'm Joe Zach and I'm super hyped.
And I'm Michael outlaw.
And I'm not quite on as much caffeine as Joe apparently is.
Right.
Or maybe it's Halloween candy.
Maybe you're still coming down from Halloween.
Everybody understands that.
This episode is sponsored by coder.com.
Now let me tell you,
coder.com.
This is a new sponsor to us.
It is the full visual studio code,
but in the cloud,
uh,
you can,
when I say that your mind's gonna be blown when you actually try it,
your full VS code, all your favorite plugins, you can go right to it, install all of your favorite
program plugins. You can use any browser to write your code. So, you know, whether that be on your
desktop, your laptop, your tablet, your, on your phone, your phone, you could write this on your
phone. You could, yeah. Tell your boss. Yeah. I'm, I'm submitting that commit right now. You'll have it right now. And they don't know
you're on the beach, right? You can access up to 96 cores because think about this. Now you're
using the cloud to, you know, somebody else's computer to, to, you know, write your codes to
take advantage of that. They've got 96 cores available for you. Now consider we just did
a hardware episode, right? We talked about, you know, Joe was trying to build his new cheese
powder rig, right? But I bet you it didn't have 96 cores, right? So think about your current rig
and how much horsepower it has and can it compete with 96 cores, right? Like I remember those old
stickers like, yeah, my other computer is a
96 core bail of cluster or something like that. Right now you could have a sticker like that.
Like, yeah, my other, my other IDE is a 96 core cluster in the cloud.
Yeah. And you really have to go to the site to check it out. So coder.com,
it really is the new experience is visual studio code in a website, but it's also still somehow
Visual Studio Code.
And that means it supports things like Outlaw mentioned, the plugins, but also supports
that real-time collaboration that I'm sure you've seen demos for, maybe you've tried.
But one of the first things we did is I invited Outlaw into my project and he started instantly
trying to mess around and delete stuff and do all sorts of terrible things.
But it worked out fine because all this stuff was kind of sandboxed and worked uh worked out really well just like it does
in visual studio code because you're literally using visual studio code in this website i it's
it's really weird to me i don't understand it but it works out really cool and the whole thing is
running on the containers in the background that you can tweak to your needs i was able to do weird
stuff like you know i say weird but it's really cool stuff.
I apt-get installed Python.
I was also able to mount the binaries for Node.js into my Docker container.
I'm not sure if it's Docker.
Into my container.
Anyway, you've got to try it.
It's a free account, and when you sign up,
you automatically get three gigabytes of disk space for your container,
three gigabytes for your workspace, and five hours of fast time,
which is just really cool to hit a button and have that thing go
in this insane mode on the Tesla.
So the containers load really fast in about one second or so,
and all you have to do is just create a new file with an extension,
or you can mount those those binaries for whatever library for whatever program language we use as well but in my case i
cloned a project opened up a javascript file and it asked me if i wanted to mount no js and i did
and that was it yep and so check it out one of the things if you're not comfortable with linux and maybe you
want to play with it but you've never really wanted to spend one up locally or or or even
have to pay for something in the cloud this is a great way to go and play on the linux command
line because you have full root access to this thing so you can go in and play with it and one
thing to keep in mind it is an alpha 0.2 release right
now. So they're adding a ton of features. There's a lot of things that you can do. Um, but it is
alpha. So share what you love. If you see any issues or anything, they want the feedback. So
make sure you go and provide it. They have a Discord channel. They've got tons of ways to provide that.
They really want to improve the platform.
So, you know, do yourself a favor,
play with it, and also share with them what you
like and what you think could be improved.
Yeah,
and I was mentioning a couple different languages
there. I personally tried out the Python
and Node. There's also Java,
C++, Go. I mean, it's container, so
you can do anything
as far as I can tell.
I'm really amazed by what you can do with it.
It seems like it shouldn't be possible, but somehow it is
and it's fast. If you just want to create
a React project, you just
npx create react app, my app,
and cd to that directory
and start it up.
You're up and running. You can actually expose
the port right there in Visual Studio Code online
and share that link out to somebody.
It's crazy.
Yeah, so I'll tell you what, you need to try this.
Go to coder.com to start your next project.
As we like to do, we want to lead in with a bit of our,
hey, we took something out here, of our news.
And first is we'd like to thank people
for the reviews that you leave.
So in iTunes, I've got PressLisa,
Techanda, Raj, Ags, HeartsLJKH.
Yeah, and over in Stritcher,
big thanks to Scott V, Hot Garbage,
Bitsui, Green Plain, MP Daves,
Joe's the Best, Stephen C. Wise, Zool303,
and one more here.
Let's see.
Drum roll, please.
Wait, how do you pronounce it?
Let's see.
This is a hard one.
Michael Tippett.
Michael.
That's always the hardest name.
Yep.
So big thank you, all you guys.
I recognize some names from Slack there,
so big thanks.
We really appreciate it.
Yep.
And one other thing I wanted to mention real quick is I managed to scam myself onto the weekly dev tips.
So if you're not familiar with that show, it's like a quick five-minute or so tips brought to you by Steve Smith, a.k.a. R. Dallas.
And I'm on episode 31.
So I've linked that episode in the show notes.
But really, you should just go subscribe to the show because it's awesome.
And it's only five minutes, which is very different from what we do.
This one might be a little bit shorter than our previous two-hour and 45-minute one.
So we'll see.
Have you guys ever noticed that programmer jokes are now synonymous with dad jokes?
Or maybe they always were and we just didn't want to admit to it. But I've got a couple. You could either refer to them as programmeronymous with dad jokes or maybe they always were. And we just didn't want to admit to it,
but I've got a couple of like,
you could either refer to them as programmer jokes or dad jokes,
but I've got a couple coming from the Slack,
uh,
that I thought I'd share with you.
So the first one from on Slack,
Mike or G,
do you hear the,
about the programmer adventure movie,
Jason and the arguments.
Oh man.
Thank you. I'll be here all week. Oh, man. Thank you.
I'll be here all week.
That was good.
MicroG is awesome, by the way.
All right.
Keep going.
You said you got another one, right?
Oh, no.
I thought I would sprinkle it in.
Throw it out.
Oh, okay.
Throw it out.
All right.
Stay tuned.
All right.
Well, today we're going to be talking about data structures.
And we kind of planned on diving in there with like arrays and linked lists and kind of looking at stuff.
But what we kind of found is it's kind of hard to talk about some of that stuff without first talking about primitives.
So we're going to do a little bit of focusing on that today.
But we still want to kind of hit the highlights of data structures.
And I think it's important to talk about data structures, particularly because we talked about algorithms and they're both like really
instrumental and huge parts of kind of computer science.
Like those two things kind of go together,
but it's kind of funny to me.
Like I keep thinking about data structures and algorithms is always living
together,
but it kind of feels like there's,
you know,
more to our day jobs than that.
Like we,
like those are parts of it.
But if you were to say that there's three
parts or four parts or more parts what would those other parts be to the day job yeah
like if you had to you know go speak to somebody you know say a class full of college students and
say hey listen you got to know your data structures you got to know your algorithms
you got to know how to name stuff how to name stuff say get communication man i honestly i think communications
i i don't think this is what you're going for but yeah no i just wanted it's like i was trying to
think of like if it felt like there should be one more word it's like these are like the tent poles
and there should be at least one i feel like i should say their data structures their algorithms
and there are working with libraries there are ticket. There's Jira. Is there a word for all of that stuff?
Problem solving.
Problem solving.
Problem solving.
Ticket juggling.
Yeah, I like that one.
You said that.
It's like dealing with crap.
Constant learning, right?
I don't know.
There's so much.
I feel like there's a despair poster in here somewhere, you know, like passing the buck.
Yeah. I feel like there's a despair poster in here somewhere, you know, like, passing the buck. Yeah, I spent a huge part of the day just reading through docs.
But, like, that's not covered by data structures and algorithms.
But it feels like it ought to be in there somewhere.
Yeah.
We've joked about it in the past, right?
Like, you see all these movies where there's people just hacking away on keyboards.
And we're like, that's not real.
Yeah, and they're definitely not data structuring.
No, they're not data structuring.
Data structuring. No, they're not data structuring. Data structuring.
Well, I can tell you, when we talked about the algorithms, I kept feeling like I wanted to say that I thought data structures were more important.
And I don't know that it's really fair to compare that, but it seems like I do a lot more thinking about data structures in my day-to-day life as a programmer than I do thinking about algorithms.
Well, it's a part of your algorithm, right?
Typically, it's, do I store this as an array?
Do I store it as a hash table?
Do I store it as whatever?
And they all have big implications on how your algorithm actually turns out.
I'll be able to speak at some point tonight.
Yeah, I guess.
So I guess I'm conflating like algorithms and like big O type stuff.
Cause I just don't really sit down and think like, Hmm, what's the runtime of this algorithm.
But I do think like,
Oh,
you know what?
I should do this as a hash table.
Cause I'm going to be referencing,
looking these things up frequently,
uh,
by,
by their name or some sort of key.
So I don't want to do this in a,
in array,
which is,
I know it's going to be slow.
Yeah.
Oh,
okay.
Oh,
anyway,
I feel bad because I don't think about it.
So I guess I'm supposed to to list everything and you're done.
Yeah.
It is pretty annoying to look stuff up in arrays, so I always notice when things are in arrays that I don't want them to be.
So you filter through them or something?
You know where I find that I think about these things a lot because they're so limited in the data structures available as in JavaScript.
Right.
If I need to look up an item directly by a key,
there's no question how I'm doing it.
I'm not putting it in an array,
but you're,
you're very limited in your choices.
So you don't really have to think that hard about it.
So,
yeah,
I do a lot of transforming in JavaScript.
It seems like,
so I'll get something out as an array.
I'll get it as an object and I need to just kind of change it to another
format.
And so it seems like I'm doing a lot of like mappy type stuff, or I'm always Googling how to like loop through'll get as an object and I need to just kind of change it to another format. It seems like I'm doing a lot of mappy type
stuff or I'm always googling how to loop
through the keys in an object.
Yeah, I'd agree.
We're going to be talking about those in a little bit
and we're going to be talking about JavaScript and a couple of other languages
so we've got a great episode in store
for you. But I want to mention a few more things
about data structures before we go on.
We didn't really kind of define
what a data structure is.
And when I say data structure,
what I mean is specifically like the Wikipedia
kind of definition here,
which is how we store and interact with data
in our programs.
Yeah.
Yeah.
That's like kind of a weird definition because like if i just assign
something to a variable that i'm storing data aren't i i'm writing to a file i'm storing data
you you definitely are but i don't think writing to a file is typically what they're talking about
right i mean it's it's going to be more of the built-in types that you interact with.
I just thought it was kind of a weird way of putting it. Ultimately, it's about how you kind of
organize your data, right? So even if you're talking about storing it on disk in a file,
how you store it, whether it's in JSON or a CSV or something,
those are kind of like data structures, right?
Yeah, I was going to say, like, I could actually see where I would have thought about it.
Like in the past, you know, when we talked about data structures, I would be far less concerned with like the variable type until it became a problem as opposed to like how I was going to persist it to disk, right? So if I was going to have some structure of a file format, right,
then in my head I might think of that as like a data structure,
albeit a custom one, but I might be more concerned with that,
if that makes sense.
Yeah, and what if you're writing a time series database?
Like you're probably going to think a lot about how you persist that data to disk, right?
Yeah, but if you were going to write any kind of database database you might be thinking about how you're going to persist it to
disk but yeah but my question is though like are we going off the rails here talking about data
structures in how they're stored versus what a data structure in a programming language is
oh yeah for sure well okay they go hand in hand.
Sort of like, I don't see JSON as a data structure. I see it as a way to represent structures of data. You know what I mean? Like the JSON, yeah, it's just, it's how you're storing
information about what the types of data in it are, whether it's an object or an array or a string or whatever so to me that's
just storing what you're going to turn back into a data structure that a programming language
understands at some point i would say it's still a data structure at but it's at like a
like a higher level like it's it's uh like a composite data structure like i realized in the
date in the json extreme like you're just talking about a string of characters.
Right.
And you're going to be like,
well,
no,
you can't talk about that.
But like,
if you were to abstract that more loosely,
like into the object that it actually represents.
Right.
So then you have objects nest within objects,
you know,
or whatever that would be a data that collective would be a data structure.
Right.
The thing that the,
the Jason is describing.
It's structured data. It's not a data structure to me or data structure. You know what I mean?
Like, I guess what I'm saying is like, there's data structures as like at the primitive level,
but then there's also like complex things like objects, which are still data structures,
like a list and array and heaps and cues and stacks.
And that's,
and I agree with that,
but I wouldn't say that Jason or XML is that,
well,
I meant that I was referring to like the,
the objects that the Jason was describing.
Okay.
Yeah.
Fair.
That's what I was getting at.
And that's why when like Joe had mentioned about storing it on a disc or
anything like that,
to me,
that's not data structures. That's just structured data stored on a disk or anything like that. To me, that's not data structures.
That's just structured data stored on a drive somewhere.
Okay, but fair enough. But I mean, like the example that I was thinking of in my head
was like, what if you were writing the data to the disk in a particular file format? Like
if you were writing an MP3 by hand to disk, right, there's a very specific structure
that that file has to be written in, you know, there's gonna be a header portion,
you know, it's gonna be reserved for certain parts, and then the music's gonna start blah,
blah, right? If you were to write a word document, you know, by hand to disk, right,
you would have a certain part of the header that's gonna be reserved for like metadata about the file, things like that, right? That's the kind of thing I was
thinking of when I was saying like writing it, writing something to disk as a data structure.
So I guess where I'm like, at least mentally drawing the line for me is totally like you're
representing the data structure in a file format or in some sort of written format.
But that's not the data structure. It doesn't turn into a data structure until you materialize it or marshal it back into something that the programming language is using.
Right. So it looks like you can look at a JSON notation and or JSON string and know that, OK, that's going to be an object with an array and some strings and some numbers, but not until that thing is actually deserialized or put back into
the language where it's used. Is it a data structure? It's just a string or binary representation
of what that data structure will be at some point. So I guess that's kind of where like for me,
I'm drawing the line between what a data structure is and just formatted
structures of data.
Yeah. Yeah.
I definitely think there's a kind of division there between like how it's
stored and whether an object in X 64 and, and binary,
depending on how you encode it is still kind of the same object, right?
It's still the same data structure to me. However,
I do think there are a couple of gray areas.
Like we've talked about inverted indexes before
and how sometimes they'll actually store an index backwards
in order to make certain kind of like clauses match.
And also there was an example a couple of years ago
where Blizzard Entertainment used to store your passwords.
They would store your password,
and I think they would lowercase the whole thing
just to kind of get around people's password typos,
and they would do the hash of the lowercase
just to kind of make passwords a little bit easier. So they're still hashing and everything, but they would just the hash of the lowercase just to kind of, you know,
make passwords a little bit easier. So they're still hashing and everything, but they would
just kind of do a little bit of trick. And I kind of think of that as a little bit data structure-y.
But yeah, I'm definitely cheating. So I threw a curveball trying to knock us off the rails
because I kind of wanted to think about things at a level like that where, you know, so many times
when people talk about data structures, they think about arrays and linked lists.
And those are data structures.
But so is a class that you create, right, where you say these are the top level and this is an inner class and here's an array.
Like I just created a data structure.
Just a very specific one.
I guess not to harp on the storage part of it, but even like how you like, quote, store it in memory,
right, is kind of where I was thinking like the storage does matter.
Oh, it does.
It definitely does.
I just think that at that point, you're talking about the data itself as opposed to the data structure.
Either way, it's the data itself.
It's just whether the data is in memory or on disk.
But yeah, I don't want harp on well
it'll make more sense when we get to my specific example okay all right well we'll get there or
maybe it won't make more sense no promises no pressure yeah if you've made it to episode 93
hopefully this isn't your first if you made it this far then you know uh you know what to expect
right but this is 94 yeah so if you made it there then you've you know what to expect. But this is 94. Yeah.
So if you made it there, then you've also gone into the future now and you're in a later episode.
Or another way to interpret that is if you've made it to episode 93, you have this one yet to listen to.
That's right.
You were starting with the zero index.
Yeah, you're in the zero index range.
I got it.
Yeah, exactly.
Yeah.
All right.
Exactly.
Data structures you use
have a big impact on resources. So, you know,
things like CPU time to complete,
memory, disk space, all that sort
of stuff. And
different languages often have built-in
support for data structures.
So, like, C has arrays
that are built into the language, right? It's actually
a part of the syntax. It's got those cute little indexes and everything,
and how you arrange it is different.
You can't easily write a true array in a C Sharp or a JavaScript.
You can't create the underlying data structure
in order to meet the traditional definition of an array.
And so some of these languages have built in support for these data structures that
are really nice.
And there's also more complex ones that are obviously composed of different various pieces.
Hey, I'm curious.
How do you say C sharp?
You can't represent the array.
So we should do a full episode on arrays and other linked lists.
But the kind of traditional definition of an array that I think about is
basically a contiguous block of memory that has
a fixed size per index, and that lets
you do different kind of math in order
to get to the 50th element or something
like that. So you were talking about the storage behind
the scenes. Yeah. You can't
do that without allocating memory because you have
to do a fixed length. You have
to know the length of the array
ahead, and you need that memory to be exactly in that location.
And if you could try to create your own, you basically have to do some sort of malloc.
And so maybe C-sharp has some sort of stuff where you can just kind of like allocate a certain block of memory this size and start chunking it up and maintaining it yourself.
But JavaScript, no way.
Okay.
Yeah, that's what I was curious about.
Because the syntax is basically the same, but you're saying that the underlying implementation of how it's handled is not.
Okay.
Yep.
And we're going to talk a little bit about some specific languages coming up here.
And we've got some really interesting stuff. I think it's really interesting to talk about, specifically with JavaScript arrays and how they work under the covers.
And sometimes an array is not an array, and sometimes it is.
So hopefully you'll find that as
interesting as I do.
Yeah, JavaScript. Everything's crazy.
Right. Everything you've learned,
throw it out the window.
That's right. I do like your next question here,
the last one.
I don't know where I am in the notes anymore.
Are you talking about the one about how would you build an array
in SQL? Yes. Yeah, I mean, it's it's a programming language right isn't it just a table well i mean
is the table contiguous in memory oh well see now now you're going to implementation
so yeah no probably not yeah so yeah that's kind of interesting and i mean javascript has an array
that's uh you know you can put the keys could be letters and all sorts of other weird stuff could be objects.
So, you know, is that it's they certainly think it's an array.
They call it an array.
If you do a type of or whatever, a type, they'll tell you it's an array.
So I don't know.
A lot of gray area.
We're going to examine some of that up close.
And I got a couple, you know, we already mentioned a bunch of different examples,
but some basic ones like arrays and linked lists.
And then you get into kind of more advanced type stuff like trees and tries and hash tables and heaps.
And that's kind of the traditional stuff that we think about when we talk about data structures.
But there's also a couple of things we've talked about like on the show,
like the inverted index for search engines.
And I'm trying to remember a couple of others.
But there's a couple of other data structures that are less common but still not unheard of.
Some pretty cool ones out there.
And also, just you create your own kind of data structure.
That's definitely outside the kind of normal definition.
But I think it still applies.
The way you structure your data and your classes is definitely going to have an effect on your CPU
and memory and disk space.
And it's definitely organizing your data.
Did any of you guys,
you know,
did you ever do like programming back when I think back to like C,
C plus kind of days,
you know,
very struck heavy where like the,
the position of it actually mattered, you know,
like if you were reading a memory stream, I mean, you could do it today. I'm not saying that like,
you can't do the same type of program today. It is done today. But you know, if you were to read
in a stream, you're like, okay, this bite through this bite represents this part. And you know,
this bit represents this,
you know,
that kind of thing.
You know what I'm talking about?
It's been a while.
I mean,
it's definitely,
it's definitely kind of stream heavy,
but you know,
or,
but it doesn't have to be there too.
I mean like you could,
I've definitely been involved in projects long ago where,
you know,
we would have structures.
We would literally have a struct,
you know,
that would represent what the data was.
And we might write that out to a queue.
We might write that out to file and then read it back in.
Yeah, I would imagine if anybody's doing video, audio type stuff, A's tag,
I would imagine that they still deal with that stuff a lot, right?
Because now you're dealing with buffers and trying to make sure things come in, you don't fill up, you don't
blow up the memory, all that kind of stuff. And that's very much there. And data structures are
going to matter a ton. The kind of the main one that I was thinking about, though, would be like
any kind of network. Oh, yeah. You're just reading from a socket, right? Like if you're at the if
you're at the lowest level, right? Like, I'm not saying you got some framework on top of it that
you're taking advantage of, but if you're actually like writing that framework, then, you know,
you might be, you might care more about that. Yeah. Cause the first few bites tell you something
about the network traffic and the next part's bit of the packet. Yeah. I mean, if you're doing
hardware level programming and actually, you know, it's funny. I've got a buddy that worked at AWS or still does work at AWS. And he was writing the software drivers for the low level
hardware of the networking, basically trying to find the fastest routes between different places.
I mean, they have a bunch of PhDs with math degrees, you know, trying to figure out the
best ways and they have to implement those things because they buy commodity hardware, right? That's
the whole, that's the thing in the cloud is hey we buy a bunch of cheap hardware we'll make it
run we'll make it run fast but there's a lot of implementation that goes on underneath the covers
on that stuff so pretty interesting yeah if you've ever seen like um code for old video games like
pac-man and stuff it actually have kind of designated regions for like the ghosts and so if you ever saw like a glitch where sometimes like
some sort of memory would get written over part of the image and you would start seeing like text
in the arcade game or whatever that was pretty cool that was actually like wasn't there like um
i forget what level it was on on pac-man but there was like a special pac-man level where
it like was an overrun error and yeah you couldn't see the full
screen but the parts of the screen you could see were kind of scrambled and you could still play
it and solve it i know yeah and you get the theory it's the the theoretical uh high score like you
get to the very end like eventually it just crashes but uh yeah they get the last couple
points it was in ready player one that's what I was going to say. Wait, does this mean that Ready Player One lied about beating Pac-Man?
Well, the movie was definitely a liar, but we shouldn't go there.
I don't remember a reference to it.
The movie was not in the book.
I don't remember this reference in the movie that you're referring to.
Oh, it wasn't in the movie.
Okay.
Yeah, that's the thing.
If you go back and read the book or listen to the audio book, because it's really good. It's Will Wheaton, right? Reads it? Yeah, President Wheaton. Yeah, that's the thing. Like, if you go back and read the book or listen to the audiobook, because it's really good.
It's Will Wheaton, right?
Reads it?
Yeah, President Wheaton.
Yeah, really good.
All the challenges in the movie were different.
Yeah.
All of them.
But it's been so long since I've read that book, though.
I don't remember it.
Yeah.
All right.
All right, never mind.
Move on.
Digressing.
The train's way off the tracks now.
Yeah, it is.
Yeah, so I got a couple of questions in here.
So we already kind of touched on them, like whether data structure are more important than algorithms.
Not for interviewing, I don't think, but for day-to-day, I feel like it is.
See, that's so surprising.
Really?
Yeah, I'm so surprised that you got like i mean i was kind of
half joking when i said like no i'll make everything a list and worry about later but i'm
kind of like not i'm kind of like you do yeah no man like it's not a problem until it is and then
focus on it like if you've read if you've used if you created a list if you used a list when you should have used it in an array,
everything's fast for small n, right?
So you're not going to know.
It's not a problem until it becomes a problem.
That's when you realize, oh, yeah, I should have used an array instead of a list.
So you're talking about micro-optimization type.
Yeah, like changing your data structure seems super micro-optimization.
Well,
for me, it's not so much
about performance as it is about me being
able to easily use it. Like, if I need to look up a
key in an array, it's annoying. I've got to do a filter
or something, or I've got to loop through to find
it. If I have to do that a couple times, like, I
feel it. But in a hash table, it
just kind of flows easily. So it's like
the shape of the object kind of represents,
you know, or at least it feels kind of intuitive to me as to how it operates underneath. So if's like the shape of the object kind of represents, you know,
or at least it feels kind of intuitive to me as to how it operates underneath.
So if I keep looking stuff up in array,
I'm going to change it because,
or else I'm going to create a copy of it.
That's a hash for those faster lookups.
Otherwise it just drives me nuts.
Okay.
Let me,
let me rephrase that.
You're going to have like your handful of things that you're going to commonly
use.
If you need it to be an associative array,
you're going to use something like a hash table
or a dictionary. If it
doesn't, then that's where I'm just like,
ah, fine, list.
Well, you know
what's funny is a little background
information when we were putting the notes together.
I didn't know there was a linked
list in C Sharp, right?
Like, because just
what Outlaw said, you use a list. You don't think about
linked lists. You don't even think about arrays anymore in C sharp. No, not really. Cause they
make it so easy to, to sort of ignore it and you're held back by the arrays, but well, that's
my point. That's exactly my point. Like if you take, let's pick on C sharp for a moment.
If you needed to store something in an array like function, like, you know, or a list of something, it's so easy to use the list in C sharp that that's the default go to until
you realize, oh, dang, I actually need to be using an array.
Like, you know, we've talked about cases
where you need to change the underlying list
as you're iterating through it, right?
You can't do that in a for each, right?
So, you know, maybe you want to work with an array in that case.
Like, yeah, that's what I mean when I say, like,
I don't think about the data structure.
So I would say the algorithm is far more important
than the data structure in your data. say the algorithm is far more important than the data structure
in your day in 90, 98% of the time. Yeah, that's probably, uh, that's a fair assessment.
Oh, what about something like a tree where you've got some data that like it, the data is a tree,
but for some reason it's got modeled in a weird way where you kind of got to like go to a list
and look up another list, go to a list to look up another list.
That's really painful to me.
Yeah, that's different.
So we've talked about that before. And this was in the handbook.
What was the name of it?
The Impostor's Handbook?
The Impostor's Handbook.
Being able to identify what something actually is. Right. And so what you're
talking about is basically somebody implemented something wrong because they didn't understand
that they were looking at a tree versus a graph, right? Like a, um, a directed graph. So
those kinds of things, yes, super painful. And that's where I guess that's that 2% of the time where it actually matters as much if not more than your algorithm because just trying to even get data into and out of the thing is just really hard.
Yeah, that's fair.
Even still, if I'm having a hard time doing a lot of lookups, I think my brain just naturally wants to kind of get it into a format that I like better first. So I kind of like the idea of like having a function like, or not necessarily function, but a process.
Or like the first part is just like getting the input, transforming it to a convenient way.
And the second step, I want to be the logic.
And the third, I want to be like formatting and output.
It really irks me when I see code that mixes those first two.
So it's like it gets part of the data and it starts going through.
And it's like it goes out piecemeal and grabs another part,
grabs another part,
grabs another part.
Like I much prefer to have like all my input stuff in one step.
That makes sense.
Yeah.
I mean like taking a more simple kind of example here would be like,
you use an int to represent a Boolean when you really just could have used
it as a Boolean, right? Like just could have used was a Boolean.
In any of these examples
we're talking about, you picked the wrong data
type. Yep.
Those actually do bother
me. If somebody
chooses an int over a Boolean, I'm like,
why? Why'd you do that?
There's some other
minor stuff too. I was working
with Gatsby recently and I still don't know why why i need to figure out the the real root uh cause here
but um my dates were getting serialized to strings uh when i was doing the graphql stuff and so i
would get in my views and it would it would be really annoying to me because i'd have these
dates and so one way it could have done it is just down in the view i could have put my little
brackets there did the date and then did a new date and then formatted from there but instead i chose to do like a map above the render
and just convert all the dates right there and then later down in the view code i just wasn't
you know i didn't have to do any formatting it was already done in the this other step so
i like to do my transforming just kind of outside that's's just a preference. I think Uncle Bob would
appreciate it.
I think he would.
Because in your view, it's just
doing the view code. It's not trying to translate the data, right?
Yeah.
I think he'd be on board
with that. I think I would be happier if I
did even more of that, if I recognized the times
I was doing that kind of piecemeal grab out
type stuff.
Sometimes you'll see that with a query, like you'll do some sort of query and you'll start looping through the query and then you'll run out and grab other stuff. I don't like that mixed with
the output. Kind of like you said about the format, like I'd love to just get that stuff
arranged. And then if I want to export it as JSON or CSV or whatever, like let that be its own kind of format output step. So I agree with the format output, but like to a certain level, I'd rather have the data
and the proper structure at the right place.
And then in the view, you can say, hey, format this date however I want it to, right?
Month, a year, or give me the time on it.
Don't do that up above it.
Let that data flow through in the proper format and the proper structure and
then handle the view however you need to.
Well,
that's still happening in what he was describing though.
But in this case,
proper structure equals a date type and not a string.
And then once you have it in your view on that date type,
you can,
you could say like,
Hey, I just give me the year portion of it, right?
Yep.
I think an example like when I used to work in ColdFusion, you would basically do the old school style.
You do a big CF query at the top.
You get your data back.
And then down in there, you would like CF loop over.
And you could do little lines of code in there to kind of transform your data or whatever.
And I think back then, I'm sure I just did the loop and then there would be like 10 lines of ColdFusion stuff underneath kind of transforming it.
But if I were coding it now, I think my inclination would be to go ahead and do the transform up there in the top of the page, the CF query, and then keep my HTML dumb just because I don't want to see all that stuff messing with my brain.
I don't want to mess up the display to declarative html code with all my crazy logic
weird formatting stuff yeah i'm just gonna throw out there you're doing your cold fusion wrong
because you should have been using a cf module or cf object i'm just saying cf module is awesome
that's that's a throwback yeah i don't know about those those crazy fuse fuse box framework stuff
like i have like five files to do anything.
That's been a few years.
Hey, so you actually have something here that I think is kind of interesting.
I'm really curious where you guys go with this.
What are the major tentpoles of programming?
Are they data structures, algorithms, API, persistence?
What's the most important to you guys?
I mean, I think the API persistence stuff, once again, that's where I spend my time.
So I think algorithms, I think about the least.
Data structures, I think about more.
But when it comes down to it, ultimately that communication, API, the organization stuff, I think this is the stuff that I struggle with and think more about.
Man, I'm going to be way more pragmatic because more often than not, you're thinking about
like your libraries, your tools like that.
That's where a lot of your time has been.
I think like just knowing, yeah, like, cause I don't think about, Hey, am I going to store
this as a, as a Boolean or an array or a hash table?
Like that, that thought doesn't occur to me that often.
But, you know, like, oh, hey, this namespace has the features that I need for that.
Oh, hey, there's this other cool namespace.
Like, honestly, how many times does that happen?
Regardless of the language, be it a C Sharp or a JavaScript,
you learn about some new library and you're like, oh, my God, that's now a thing. That's amazing.
Like that's the type of thing. Those are the APIs, you know,
that we think about.
Yeah. If you really know your framework, it's like, should this be a hook?
Should this be as part of the router? Should this be part of the,
the whatever like that,
knowing the best place to do stuff and in the proper patterns for what you
want to do can save you a lot of, a lot of work and a lot of headache.
You know what on that?
So, so I want to go back to that real quick, but I'll say for me, the, the, the tent poles
of programming for me is domain driven design actually made so much sense to me.
Like don't program from your database program for your business case
program for the use case. Like to me, that's the one thing that I don't think is one of the pillars
of programming, but should be taught more, right. You know, write code to the case that it's being
done because then everybody can understand it. Um, but so what, what did you just say that I've already lost it?
What were you just talking about?
Ah!
Cold fusion?
No, not the cold fusion.
You talking about like with the libraries?
The libraries, yes.
So one thing I was going to say, what you said was so important
is if you know your framework,
then you'll know whether or not you should choose to use a hook or something like that.
Right. If you're using a library, you don't have to be.
It's not like you have to memorize the whole thing at once, but go through the documentation and skim every single page.
Just skim it, because then something will stick in your head so that later you're like, oh, I saw something, right?
There was something that stuck out and I'll know to go back and look for it, right?
I know I do that with just about any framework.
Build a mental index of the documentation so that you know where to go for a particular thing.
It just tickles your mind, right?
You're like, hey, wait a second.
I remember seeing something about this. I need to go back and look at mind, right? You're like, hey, wait a second. I remember seeing something about this.
I need to go back and look at it, right?
Yeah, I mean, like an example,
a great example of this, though, that I think of,
when you think about, like, if you didn't know the framework
and how it would be like form binding, right?
Like, if you didn't know, oh, hey, there's this way
that you could just bind the data structure
straight to the form, and instead,
you start wiring up controllers to handle all of that for you.
Right?
Like, you just wasted a lot of time and code, right?
And I did back in the day.
We all did.
Yeah.
I mean, when you were talking about ColdFusion, like in ColdFusion, that was truly, that was
back when, if you think of ASP or even PHP, which I'm not as familiar with the
newer frameworks and stuff, but you wrote your HTML and then you mixed a bunch of server-side
code into it, right? To write the additional HTML you needed. So there was no such thing as
form binding. You wrote an HTML form and then you wrote JavaScript or whatever to handle it.
And when I moved over into the dot net
world i carried that pattern with me because that's what i understood yeah not knowing about
the binding right like not knowing that you could have a form on there and just be like hey bind this
to a data what i didn't know that was real so yeah and we talked about how that first language
can really have a big influence on the rest of your programming habits.
Oh, yeah.
Yeah, I'm still cold fusion programming and C sharp 8.
Yeah, baby.
You know, there's one with the rollback.
I was listening to an episode of the rollback, and I think it was Chris.
I was talking about how to read a book.
And it's funny.
There's actually a book called How to Read a Book.
It's like 400 pages.
But basically, it kind of boiled down to, I just read the summary of it,
was first you kind of go through and you skim
and you're supposed to kind of highlight the things that catch your interest.
And then later, you kind of go back and you really focus on those things
that you highlight and you kind of drill in from there.
But the idea is kind of like you said, Alan,
where it's like first you kind of need to get to get a lay of the land otherwise if you always kind
of like stick in chapters one two three of the book or whatever you kind of um don't see the
whole thing before you get started and you could be missing big chunks of the big picture and be
doing things in an inefficient way man that sounds good for technical books i don't know about for
like reading for pleasure though yeah definitely not so you're saying that for technical books. I don't know about for like reading for pleasure though. Yeah, definitely not.
So you're saying that for technical books, you should not try to read it from cover to cover.
No, like kind of skim it cover to cover.
I haven't actually tried this, by the way.
This is an idea, but just don't try to focus on every word. Like if you're having a hard time with something, just kind of move on because maybe you'll see some other example or something later on to help you fill in the blanks.
And ultimately, if you never do figure that out the rest of the book, you're just going to come back through and kind of hit those highlights, trouble spots anyway.
So you can spend more time on it then.
And that totally makes sense, too, if you think about it.
How many times have you read something that you're like, oh, I understand that.
And you go sit down on the keyboard and you go to type.
You're like, I don't remember anything i read and i gotta go back
through the chapter and basically use it as a reference right like what did they do like it
seems so simple yeah i thought it was really interesting because it's total opposite of how
i usually read tech books which is like read chapter one super i'm super pumped about i tell
everyone they need to go buy it i read read chapter two. I think I finished it.
And then I sort of remember chapter three.
And then that's it.
The rest might as well not even exist.
The other 15 chapters.
Right.
Yeah, I've definitely had some books like that.
I mean, I try to go cover to cover, kind of like what you're describing, Joe.
But they're definitely in some books.
And in fact, there was a recent one where I just got about halfway through it.
And I'm just like, okay, I'm done.
I can't. That's $'m done. I can't,
that's $30 gone.
I can't,
I can't finish it.
Sadly.
Yeah.
There's been a few like that for me too.
Well,
I do have two books I've started reading cause I'm an idiot and I'm going to
try and just go,
I'm going to try and blast through.
I'm going to try this technique.
I've been highlighting already,
so I'm going to try,
I'm going to pick one.
I think I'll start with the,
uh,
the react book since I'm further and I'm just gonna blast through it i'm gonna highlight and
then we'll see how it goes so just skim through it the first time highlight stuff of interest and
then go back through it a second time yep i think that's probably a good idea because i know the
little react projects i've been playing with i keep like redoing like the same map like i do some
little stuff i'm like okay cool i like react but none of them have routing yet because i haven't
got to the routing chapter yet. I don't know
how it works.
There's probably some stuff in there that's important.
Let me ask you this then. If you have
a book on React, isn't it already out of date?
Yeah, it was
yesterday. It was published
the day before.
It could have been published today. It was already
out of date by the time it
went to the publisher.
Totally. There's a out of date by the time it went to the publisher. Yeah.
And there's a ton of stuff in jQuery
I've never even seen before.
This is just par for the
course.
Cool.
Alright, so
moving along. I wanted to take a quick
second to ask you to please
leave us a review. We got some great ones this time.
We really appreciate it.
And I was actually looking at the amount of reviews we have and really appreciate them because we do have a lot comparably compared to other podcasts.
And it's really not fair, but I appreciate it. of our listeners left a review, we would be sitting pretty friggin' pretty.
We would be sitting good.
I forget the expression.
I'm tired.
But it would be so huge.
Even if just 1%.
So if you could be part of that 1%,
if you could hook us up and help us out,
it would be massive help for us.
I would really appreciate it.
And then the other 99% of you, we need you to tell a friend.
Yeah, there we go.
There we go.
If you don't want to put your fingers on the keyboard, which, you know, I get it though.
I get why people don't do it because like me, I listen to podcasts while I'm driving.
I listen to podcasts while I'm not in front of a computer, right?
And so it's actually,
Oh,
I need to go do this.
And,
and so we,
we really do appreciate it when you guys do it,
but yeah,
totally.
If you're not going to do it or you're not going to remember,
you know,
while you're listening,
just take the air pot,
you know,
take the butt out of here and tell somebody,
Hey dude,
you should listen to this.
Like,
yo,
you need to listen to this.
That's right.
Hey,
you,
you and you,
you absolutely have to listen.
Wow.
That,
that took a dark turn.
Yeah,
that was dark.
Sorry.
No,
that,
you know,
all right.
Well with that,
let's take a moment to head into my favorite portion of the show.
Survey says, Survey Says.
All right. So back a couple episodes now, we asked, what's your social platform of choice?
And your choices were Facebook for the old world or Twitter.
It's the best way to catch up on my co-fayfay or Snapchat because a picture is worth a thousand
words or my favorite Instagram because a picture is worth a thousand hashtags. Or LinkedIn, it's all about keeping it profesh.
Or Google+, I like the dust and cobwebs.
And lastly, social, get off my lawn, kid.
What, you want the government to know everything?
All right.
That's awesome.
Hey, a quick reminder reminder by the way if you
find if you search for joe zach on linkedin i will totally friend you as long as you're not a recruiter
yeah same here i'll even friend you if you are a recruiter yeah i'm not gonna draw a line i'm weird
about it hey yeah plus though did you guys hear it shutting down next year i think august what
did you say now like google plus is shutting down next year, like in August, I think.
Yeah.
I think it had a bug and they're just like, not worth it.
Not worth fixing.
Security issue.
Man, that's going to require 20 hours.
We're done.
Yeah.
But, you know, I mean, it's not unlike Google though, right?
They're like, hey, we created something.
We don't like it.
Yeah.
Gmail's going next, by the way.
That's out at the end of this year. Don't even say that. Don't even joke about that. hey we created something oh we don't like it yeah gmail's going next by the way that's that's
don't even say that don't even joke about that dude you know how bad that would mess everybody
up yeah i hear great things about flutter but the part of me is like i don't know i remember reader
yeah yeah i remember everybody's lost faith all right so so who's going first this time is this
joe i can't remember alan you go first. I think Joe went first last time.
So you go first.
Man, I honestly, I have no clue on this one.
I think I'm...
Let's go with Facebook and I'll say 17%.
Okay.
I'm going to say Twitter because you can follow Elon Musk and he does crazy stuff.
You want to put a percentage on it?
Yeah, you got to put a number.
29%. 29?
That's insane.
For Twitter.
No way.
That's what it is.
That's probably what it is
um okay well
then
neither of you got it got the right
one your your
percentages are both off but
between the two of you
one of you is more right than the other
and that's joe
really yeah
so is it is it linked in all right so i kind of i gotta assume that
people are messing with us though let's get off my lawn because google plus was far and away the
winner no that's not possible it could be your favorite and you still not use it that's true
because that's maybe that's why it's your favorite and you still not use it. That's true. That's true. Because that's what everybody's doing.
Maybe that's why it's your favorite.
Yeah.
Because nobody ever bothers me here.
It's my nice, quiet place.
Wait, when you say by far, how much was this?
It had 42% of the vote.
Wow.
Wow, dude.
So I'm pretty sure that people were like, you know, having fun.
They're like...
Yeah, I think it's more likely that people just like dust than cobwebs.
Yes. Now, dude dude that's the thing if you actually go into google plus it is a much nicer place to find information that you care about but nobody uses it like or well if the information you care about
is dust and cobwebs then you're going to find out a lot about it true yeah true that yeah second was surprisingly my people social get off my lawn kid yeah i thought that i i thought
that was surprising how far how how much was that uh i mean they all go downhill from there like
that one that one was like 21 of the vote okay so Okay, so we've hit 60-some-odd percent in the two, so that's pretty good.
Yeah, I mean, then Twitter for third and Facebook for fourth, and they were both close.
Like Twitter's 13%, Facebook was 12%.
Where are my snaps at?
That was last.
Definitely last.
Super surprising there.
I actually thought that one would rank a little bit higher.
I thought that one would be more popular, especially among a younger crowd.
But wait, isn't Snapchat all about getting rid of evidence, right?
I mean, I think that's how it started its thing.
That's why I was thinking it'd be more popular among
a younger generation because
that's not where your parents
are kind of thing.
I will probably never be
on that because I don't trust anybody that
says that there's no history.
That's a lie. You can't take a screenshot?
Yeah.
I don't believe in that, but
yeah. Yeah, they started on a wrong premise. I mean, I don't believe in that, but yeah.
Yeah.
They started on a wrong premise.
All right.
So what do we got for today's?
All right.
So today's survey or this episode survey is what do you value most in a job?
And your choices are pay.
It's all about the Benjamins. Or tech stack, I need to remain interested. Or commute,
or the lack thereof. I mean, I love listening to coding blocks and all, but a new set of tires
every month is ridiculous. Or location, location, location, just like real estate. Or team, I need to be surrounded by people better than me so I can grow.
Or industry, I want the type of problems I solve to matter to me.
Or benefits, I like to take off for the summer.
And lastly, work-life balance.
I have a life outside of the summer. And lastly, work-life balance. I have a life
outside of the office.
I'm really going
to be interested
in what these answers are.
I don't know.
I don't know.
Yeah, I have my strong opinion
about what's going to be
far and away the winner.
Oh, you want to predict?
I don't want to taint the...
I don't want to taint the survey.
No.
I'll wait.
Honestly, every one of these have been relevant to me at a different point in my life.
So I honestly don't know how this one's going to pan out.
So we'll see.
This episode is sponsored by Datadog.
You've heard us tell you about Datadog.
You know that their software is a service monitoring platform that gives developers and operation teams a unified view of their infrastructure, their apps, and their logs. But did you know about some of these killer features? setup or configuration. By continuously examining application performance data,
it identifies anomalies like sudden spike and hit rate that could otherwise have remained invisible.
And once an anomaly is detected, Watchdog provides you with all the relevant information you need to
get to the root cause faster, such as stack traces and error messages and related issues
from the same timeframe. And then there's Tr trace search and analytics. Trace search and analytics allows you to explore, graph,
and correlate application performance data using high cardinality attributes.
You can search and filter request traces using key business and application attributes,
such as user IDs, host names, or product SKUs,
so you can quickly pinpoint where performance issues are originating and who's being affected.
Tight integration with data from logs and infrastructure metrics also lets you correlate
these specific trace events to the performance of the underlying infrastructure so you can
resolve the problem quickly. And let's not forget about logging without limits. Logging without
limits lets you cost-effectively process and archive all of your
logs and decide on the fly which logs to index, visualize, retain for Analytics and Datadog.
Now you can collect every single log produced by your applications and infrastructure
without having to decide ahead of time which logs will be the most valuable for monitoring,
analytics, and troubleshooting. Yeah, and Datadog is offering our listeners a 14-day trial.
No credit card required.
And as an added bonus for signing up and creating a dashboard,
they'll send you out a Datadog t-shirt.
Head to www.datadog.com slash codingblocks to sign up today.
All right, so we teased it a little bit,
but now it's time to finally talk about primitives.
And what I mean by primitives are the most basic types in a computer
programming language that all other types are built on.
They're kind of like the atoms of the universe,
right?
It doesn't get any smaller than that.
And primitives refer to two things and it gets a little grain,
a little bit weird,
just like anything else.
Cause there's like the definition on Wikipedia. And and then there's what happens in the real world.
And as I started reading about this, I started seeing just how much wacky, crazy stuff there was out in the real world.
And I was like, this has got to be a whole episode.
So I just thought it was really cool, and I hope you guys think it is also cool.
Oh, yeah.
And those two types that i mentioned are the basic types
and those are things like the uh you know those elements that can't be broken down any smaller
this seems like a boolean like it doesn't get any smaller than that right but then there's also
built-in types which are like things like um you know the c-sharp string which is built in and it
has to be built in we kind of discussed that a little bit but it's not considered a primitive there's also things like date time enums and other stuff and
list has a list the language list has lists uh built in but they aren't considered a primitive
because they're composed of other various parts and so wikipedia has a list of the basic primitive
types we're going to deep dive these here in a second.
And they have it listed as character, integer, floating point, fixed, and bool.
And then there's a reference type for like things that like pointers. So I am looking at my notes here.
I'm not very good with notes.
My wife says the same thing.
I need to write more.
Yeah.
Or maybe I should read them after I write them.
Well, I have something I want to interject, but I'm kind of thinking maybe it would be better because we're going to dive in on the primitives here in a minute.
So maybe I'll hold off for that.
Yeah, we're going to have some pretty heavy stuff in a minute.
What notes did you have in there, Joe?
I just didn't realize it was so short before the next section.
Okay, well, then I'm going to go ahead.
Okay.
So, because let's go
ahead and take a moment to dive into some of the primitives right is that you're okay with that
absolutely so uh i mean we've hinted around about some of them but the one that like kind of
struck my fancy that i thought was kind of interesting to dig into that I never really thought about were floats and floating point.
Okay.
Yeah.
So,
so,
um,
okay.
So for anyone who's not familiar,
right?
Floats floating point is for decimal kind of numbers,
like real numbers that have digits after the decimal point.
Right now,
have you ever questioned why is it called a float?
Yeah, because we also have fixed points, which also have a decimal point.
And there's obviously some sort of distinction there, but I've never been too clear exactly
on what that meant.
Alan?
Before recording or before setting up the notes for this, I don't think that I ever spent that much time digging into it and then found some pretty interesting things while we were.
I know the point kind of moves, so it may be far to the left or far to the right.
But I don't really know what that means under the covers or what the true significance is other than it seems like it should be efficient.
Well, okay.
So in a nutshell, though, that is the answer, why it's called a float,
is that because the decimal point isn't in a fixed position.
So you did mention fixed.
So you have a fixed data type for for decimal in which
case um let's say okay you have you have whatever the data structure is that you're going to use it
you know in a fixed place in a fixed decimal point you're going to reserve automatically a portion of
that space for what's to the left of the decimal and what's to the right of the decimal, right?
In a floating point, you're not doing that.
So, you know, in doing some reading about this, though, there were some – we'll have links to some really great articles.
John Skeet had a couple really great articles written up, and it kind of made me think, like, my God, what does that man not know about C Sharp?
Because obviously, like, his articles were more coming from a C Sharp point of view.
But he linked to another one that wasn't.
Well, actually, no, I take that back.
It was from a.NET point of view.
But regardless, though, the concepts and the theory behind it
could apply to any kind
of language, except maybe JavaScript, because nothing does. But yeah, I mean, you think about
like, why do we need a floating point, right? Like, you know, why is that even necessary? So
we know how to, we know how we can represent integers in a binary form, right? Like that, that we know how to do,
right? So if, if I asked you, you know, to represent the number 10 in binary,
if we only use like four, you know, binary positions to do it, it would just be 1010,
right? And if I asked you to represent a three, then you only need two positions, you know, the right most positions
to be both ones, right? So we can represent these integer-based numbers in binary easily,
and we can even reason about it, right? Like, you know, you can think in your head, like,
what the binary representation for the number one would be and what the binary representation for
the number three would be, right? But representation for the number three would be. Right.
But if I asked you, okay, how would you represent, take those same binary numbers, one and three,
and how would you represent one divided by three in binary?
Right.
Oh yeah.
That's pretty nasty.
I can't remember how to do that.
Yeah.
That gets more complicated.
I mean,
don't even,
don't even think about it.
Forget about binary.
Like just even how would,
how would we as humans write it out?
We can't,
we can't,
we have to use symbols to,
to write out the expression of what one divided by three equals.
We would have to write out like a 0.333 and then we would draw a line over the
last three to represent that. Hey, that last one goes on forever because we, we don't even have a way to represent that like 0.333 and then we would draw a line over the last three to represent that hey
that last one goes on forever because we we don't even have a way to represent that on paper let
alone how could we do it in binary form right and and then you run into problems where it's like
okay well what if you did one divided by three plus one divided by three, right? You know, on paper, we might just end up with a result that is more
like, you know, 0.6667, because we'll just, you know, round up that last digit and, you know,
consider that approximation to be good enough, right? Maybe we do that, or maybe we do the trick
from the last time, and we just do the line over
the six again and say like hey this is just going to repeat forever right but the point is is like
then i'm pointing out there is like two things number one is we can't even write that we can't
even represent this data on paper let alone in a computer and we've already shown how like more
like commonly we will just make an approximate
proximization and be like that's good enough that's acceptable right so so how how does this
actually get stored in in a binary form right so for a floating point number, you have, there's three parts of it that are going to be
important. There's the sign, there's the base, which is, depending on what you're reading,
you can might read it referred to as the mantissa or the significant. And then there's the exponent.
So it'd be something like for a binary floating point number,
it would be something like negative one times two to the n,
for example, right?
Two being your base, n being whatever the exponent is,
and the negative one being the sign.
In this case, you're trying to make it negative, right?
Yep. So those are the three parts.
So remember earlier when I said that, well, the data structure of how you store this in memory
does matter? This is kind of what I was thinking of was because I knew I was going to be bringing
this up where if you wanted to store that, you're storing this in memory, right? And let's say for a 32-bit float,
you have these three parts to store. So one bit is reserved for the sign,
23 bits are reserved for the mantissa, and eight bits for the exponent. And for the double,
it's a little bit larger. Still one bit for the sign, 52 bit for the mantissa, and 11 bits for the exponent. And for the double, it's a little bit larger, still one bit for the sign,
52 bit for the mantisa and 11 bits for the exponent. But the point is, is that's a primitive
in almost every language we've ever talked about, right? Like float is very common primitive,
but it's that one data structure is made up of three very important pieces of information.
And if you read these articles that I'll link to, like, oh my God, it gets even so much more complicated.
Did you do realize that there's a such thing as negative and positive zero?
Yes.
Yeah.
Only because of preparing for this episode.
Okay. Well, aside from preparing for this episode, because I never would have thought about it, never would have cared.
But it turns out, deep in the bowels of your computer, yeah, that's actually a thing.
It actually does matter.
But more often than not, it doesn't matter to anything.
It's just technically you can get an operation that would produce a result that would be negative zero, right?
Does negative zero equal positive zero?
If I remember correctly in the article, I didn't – I tried to actually pull down – there was a code example that came with one of the articles, and I tried to find it, but it had actually been pulled.
But if I remember right, negative zero did equal.
I mean, it would certainly make sense.
Everything would be broken if it didn't.
It would have to.
I'm going to try it. I don't have a C-sharp compiler with me to double-check that.
Isn't it a.NET fiddle?
JavaScript has that, too. And negative zero is equal to positive zero. Wait, wait, wait, wait. You, you're kidding
me, right? You're not going to take JavaScript as any kind of source of truth for anything.
That's truthy. Yeah. Truthy. Um, yeah, but you know, so, so the interesting point there there though is that it's because
that of that uh exponent that you're using where you can because that exponent could be
um can determine like which direction you know where the decimal point is going
right so that's what's making up the point that that's why it's called a float.
Or though more technically in dot net, you would have system dot single and system dot double and system dot single is technically what a float represents. Right.
But, you know, if you were to consider the like, what's the what's the alternative to that, which which is kind of what you hinted at, Joe, when you mentioned the fixed point number.
So, you know, think back to, like, currency from, like, if you remember any Visual Basic days,
or in SQL Server, if you wanted to use the money and small money data types, right? It has a fixed decimal
point, right? So in that type of data structure, you're kind of, you're, you're, you're automatic
because you're automatically reserving space for those decimals, then you're kind of capping
what the range of that value can be. Does that make sense?
Whereas with the float,
because that the decimal point can move,
then it has more range as a result of the number that it can represent.
Oh yeah.
I remember in SQL,
you specify,
you literally say how many to left and how many to the right.
It's like decimal 10 to right.
You'd be 10 digits to the left and to the right. Yeah. and then there was another thing that i kind of hinted at too where
you might have recognized or heard me say that a binary floating point number
which i never had i'd never really given much thought to that either but um it turns out that
there's there's decimal floating point numbers and there are binary floating point numbers.
And at least in the.NET world, float and double are both binary floating point numbers.
And the decimal is a decimal-based floating point number.
Decimal-based floating point number. Hmm. Decimal based floating point number.
So remember when I was talking about like the,
the example of how,
how you're the floating point number is trying to represent a formula,
right?
Negative one times two to the end was the example that I gave.
Yeah.
So change the two to a 10 for example.
Like what if instead of a base two,
it was based 10. So, if instead of a base two, it was base 10?
Okay.
So, but the way I, and I couldn't quite find a clear definition on the float version, but
the decimal version would be like take the negative one, whatever your sign is.
I'm using negative one just to emphasize
the sign but um negative one times the mantisa divided by 10 to the exponent and that was like
one bit of question that i was that is still a little unclear to me like well
is it well that's how you get your floating decimal point, right? That's what that power would be, yeah?
Well, but the point being that the, it's,
because I could have sworn that like what I was reading about the floats
is that it wasn't like the mantissa times two to the n,
but it was like the sine times the base times the exponent, right?
Does that make sense?
And specifically with the decimal, though,
in this article that John Skeet had,
he specifically calls out that for the decimal type, it's the sign times the mantisa divided by,
uh,
10 to the exponent,
you know,
and not exponent trying to decide like where you're placing your,
your decimal point.
Right.
Um,
but yeah,
I mean,
it was like so much more complicated than like,
like just,
just the,
the,
this one primitive right was way more
complicated than i had ever considered it it was or actually is because then there were cases of
like um oh what did they call them uh it was it was well there were nans but then there were signaling and quiet Nans. Have you heard of these?
No. Like you might
see it as S-Nan or Q-Nan
and
it's not honestly
they're both trying to represent not a numbers
situations but
the difference between them are kind of the quiet NAN.
It says is,
is used to signify that the result of a mathematical operation is undefined.
Whereas the signaling NAN is used to signify an exception where the operation
was invalid rather than just having an indeterminate outcome.
Because like,
if one of the things that I was reading correctly was saying that like sometimes these there were like um one of these
articles i don't remember which there was like like errors that would be thrown but like they
were kind of trapped internally like you don't you don't see them happen but like they were kind of trapped internally. Like you don't, you don't see them happen, but like internally it might get caught or something like that.
If I was reading it correctly,
like subnormal numbers,
you know,
like,
yeah,
I mean,
it was totally weird.
Like how some of these things would represent like,
okay,
so I told you like how you would represent a float,
but then using that same data structure,
how would you represent not a number or how do
you represent positive infinity versus negative infinity and things like that. And then there
were like all these weird cases where, and this is where like the negative zeros, um, you know,
negative versus positive zero might come into play. Um, where like, well, one of the examples was like if you did an infinity divided by an infinity,
maybe you might think that would be a one, but it's not.
It was like not a number is the result, I think.
Okay.
Yeah, I don't know how you could ever arrive at that.
How you could arrive at what?
Infinity.
You can't ever divide infinity by infinity because it's a never-ending thing.
There's no such thing, sort of. It's like real but not real.
Yeah, I know. But at the same time, we're also
taught that if you have the same thing above
the same things below, then that's automatically a 1, right? But it's not.
That's why I said you might be tempted to think that it's a one um
yeah i mean like floats are so much more interesting to me now than they ever were
um we didn't really talk about what they were for right like uh you did uh you saw something
interesting about um discrete and continuous values yeah so while I was doing some digging into this, like one of the things
that came up and we'll have a stack exchange link to it, there was some really good answers
because really, I think what I looked up is why would you use float or double versus
a decimal or something? It's always do fixed, right? I mean, in your mind, like if you're, if you're thinking in terms of your
dollars and cents fixed makes a lot of sense because you're like, Hey, if, if I have $20
and 35 cents, I want $20 and 35 cents tomorrow and the next day and the next day, I don't want
that to change. Right. And floating point numbers don't give you that guarantee. They're not super precise like that.
And that's kind of confusing to me just as a person.
Like, well, then why would I ever use the other one?
It doesn't make any sense.
And there were some really interesting breakdowns of why you would do this. So this article, like I would read through
all the answers because while some of them are probably more right than others, it's the
perspective of the different programmers that really matter. So, um, the ones that really jump
out at you are people that work in physical type, um, calculations. And so what it boiled down to is they said, why would you need floating point math?
It's basically for continuous values.
And that was really interesting, not more static values.
And one of the examples somebody gave that was really interesting is if you're programming
a video game and you're having to do the velocity of a bullet that got shot out of a gun, it is way faster to impact the overall thing. But the math that can be
operated on that thing is significantly faster than what can happen on a fixed decimal. And so
in that case, it makes a lot more sense to use the floating points. There were other things like what
Michael mentioned with the range. It's really weird. I forget. I've actually got on the notes here.
One of them. So decimal, a decimal technically takes up more storage than a double, like quite
a bit more storage than a double, but because it has fixed places for what is on the, what'd you
call it? The Mentesa, basically the full, the integer,
the integer value versus the decimal portion of it. It technically has a smaller range of
whole values that it can go across because of that fixed decimal spot. So when you think about
those things and you get into it, the use cases behind why you would use a floating point versus the fixed point,
there's a lot of reason for it. Like they even said in financial modeling, right? You wouldn't
use a fixed point because you're trying to predict things. And again, when you're trying
to predict things, the accuracy to the 20th decimal place doesn't matter as much to you as the speed at which
you're trying to calculate those things because it's a continuous calculation.
When you are trying to balance your checkbook, you want that fixed. So you have to think of
the use case. If you're doing physics or life-based or modeling or that type of stuff,
then the floating point might be what you want to go towards.
So really, really interesting answers from multiple different perspectives
from people that do different types of programming
that really kind of help bring to light when you would choose one over the other.
Well, I got something I want to expand on that,
but first I want to clarify, like,
you weren't suggesting that a decimal was fixed, though, right?
Well, it's got a set number to the left and to the right.
Yeah, hold on.
You're talking about fixed.
But are you thinking about like in SQL Server?
Because like if we're talking about like in a C sharp, right, it doesn't.
It is a floating type so here you go like so there's actually an article
that i linked to um and here i'll just read the article because it'll make more sense than if i
try and do it out of context there's an interesting thing to point out when comparing double and
decimal the range of double is plus or minus five times ten to the negative 324. So five with 324 decimal places of precision
to 1.7 times 10 to the 308. While the range of decimal is negative 7.9 times 10 to the 28th. So compare that to double, which is five times 10 to the negative 324.
And then the opposite end of that is 7.9 times 10 to the 28th.
So it says,
in other words,
the range of double double is several times larger than the range of decimal.
And the reason for this is that they're used for quite different things.
And this is,
so double is a 64 bit floating point.
Number decimal is 128 bit floating point number with a higher precision and a smaller range.
So it's the precision that you get because of where that decimal lives,
I guess,
is why you have a smaller
range of numbers that it can actually fulfill.
But it's not a fixed point is the point that I wanted to make, though.
It is still floating.
Okay, I got you.
But yeah, I mean, kind of going back to the cases, like when you would use it, though,
I mean, like, yeah, I had my own kind of write up here just related to the floats is that, you know, kind of similar to how you were saying, like, said, if you're representing money, then you probably want something that's, you know, that's precise, you know, maybe a fixed
decimal type, um, would work best for you or, or a precise type like the decimal instead of,
uh, a float or a double. But, um, you know, if you're, if you're doing anything that's,
if you're using this variable to represent anything from the real world, then like a measurement of a piece of wood, for example, then the float or a double might be good enough because the likelihood that you're ever going to measure that thing, you know, the same, like, yes, technically, like John Skeet made a point of like saying something
along the lines of the, yeah. Okay. Technically you could measure something and say like,
that is 13 centimeters, but that the, in the real world, if you're going to measure something,
the likelihood of you measuring it exactly super precise, super precision, uh, you know, down to
like 96 decimal places, right? Like that's probably not going to happen, right?
So he says it is as if it's a man-made value, such as a currency,
then you're probably better off with a decimal float point type.
But for values from the natural world, like lengths and weights,
then a binary is going to be better off. And, uh, the, the, both of the articles I
read had measurements that like, um, one of them said that if you were to use decimals instead of
floats as your default, uh, your number of choice, right. That in terms of the calculations,
decimals were an order of magnitude slower than floating points,
as well as taking up twice the amount of storage in the case of a double versus a decimal,
like you mentioned. And then in John Skeet's write-up, he had some measurement that was like, it was 40 times slower to use the, the
decimal type than using the float. Now, you know, I don't know how old this article is and, you know,
what kind of hardware it was at the time. Um, so maybe those, maybe that still adds up, but
you know, there was another point too, that I had read while researching this was like, well, why would you even bother with
the flow? Like if you did
for example,
like one of the things I read, like if you had
you know our
love of var, right? So if
you said var i equals
five, right?
Then by
default, it picks a 32-bit integer to represent that
but why right probably because it's the easiest to store right well it it's actually based on
the system so if it's a 32-bit system there then the argument was, well, you could pick a smaller storage type to store that, like a 16-bit integer, for example, could technically be enough to store it.
But if the hardware itself is 32-bit, then it's going to be faster to use a 32-bit number.
Same for the floating point, right? Like, you know, floating point arithmetic is, is, you know,
there's a lot of optimizations that are already happening for that.
Hey, so, so check this out, going back to the double, the floating point, this was interesting
also in that one article that I read the snippet from earlier, this was really cool. So what they
did, and it's pretty simple math, so I don't think it'll be too confusing to talk about. They took the value 10 and then they
multiplied it by 0.1, a double value of 0.1. And then what they did is they, so that's 10 times
0.1 is one, right? Or is that what they 10 times 0.1?
The,
they did something weird here in the thing,
but at any rate,
so it should come to 0.1 and then you're going to add 0.1 10 times,
right?
That's,
that's essentially what you've got.
Oh,
that's what they did.
Okay.
So 0.1,
they multiplied it by,
you'd expect to get one,
right?
0.1 times 10 is one,
but then they took the 0.1 value that they had assigned to x and they said do add it together 10 times and what would
you expect to get you'd expect to get one again right 0.1 plus 0.1 10 times should give you one
here's the thing and this is what's interesting. It doesn't come out to that. When they do that, at least in C Sharp, they got 0.999999 something, 8, 9, however many number of nines.
And what they said was the reason is this, and I think, Outlaw, you would either mention this or alluded to it just a little while ago.
Basically what they said, in most systems, a number like 0.1 cannot be accurately represented using binary. So there is,
there's going to be some form of, of arithmetic precision error when you're doing this. And so
when you take that value and you start adding it up multiple times, instead of getting that nice,
neat multiplication that it can just shift those bits and make it happen really easy. Now it's trying
to add these imprecisely stored numbers. And so you have this little bit that's off at the very
end of it. So that's your precision error. And it's all because of how that data is stored in
binary. Now it's way faster. So if you can live with that, I mean,
God, I don't even know what place this is. It looks like it's probably in the 15th place
that it's off by, you know, whatever that is one, one of those. So if you can, if you can take that
hit and like he said, if you're modeling something in the real world, it's not probably money that you need to make sure stays the same.
Then you can probably take this hit and it's not going to hurt anything.
So check this out.
I just ran a little test.
3.2 is one makes it a float number
equals
3.2
which is a decimal
number then you get false.
So 3.2 F is not equal
to 3.2. And if
you actually print out these numbers you'll see that
the floating point ends up being
3.205
and the decimal ends up being 3.205. And the decimal ends up being 3.202.
It's kind of funny that it ends up being a big difference.
But if you are trying to compare two numbers,
even if you look and it looks like 3.2 should equal 3.2,
it may not because of those underlying primitives.
Yeah, the equality thing is probably a big deal, right?
Like that's something you'll have to pay attention to if you go to use these things is because there's going to be some margin of error that you're going to have to account for.
So just like you said, it's not going to equal equal the other one.
And you're going to look at it and be like, well, why?
I know that that's the same.
But no, you didn't.
The storage behind the scenes is what matters.
And so they don't equal out at the end.
So it's pretty cool.
Even in the article that I had, they had a similar example where it was like,
if you did something like that and you would expect to give like a 10% discount,
but because of these kind of rounding errors, whatnot, you actually end up giving an 11% discount when you meant to give a 10 because the way it ends up breaking out.
Yeah, I mean, after digging into floats, it's definitely my new favorite data structure, so I'm going to use it for everything.
So you can see that in an upcoming pull request. But, you know, I mean, even in what you were describing, Alan, there was,
um, you have to take a moment to even talk about like precision and accuracy and make sure that
you're like, okay, let's lay some, let's lay some groundwork here and make sure that we're all on the same page. Right. And so precision refers to the amount of information used to represent the
number.
So four decimal places,
right?
Whatever.
Yeah.
You know,
like if,
if you're using 32 bits to represent that number,
that's your precision,
right?
But your accuracy indicates
how close to a value it is to its true value, right? So this is where the floats, you know,
their accuracy isn't like exact, right? They're close, they're approximations.
And I think it was still in the John Skeet article. It might've been in the other one,
because there were like three different articles that I like really used as the
reference when I was learning about this,
you know,
deep dive on floats of all thing.
But there's this great,
there's this great idea here that was like,
Hey,
okay,
we're all familiar with pie,
right?
The,
the,
the number,
not the food or, well, okay. We're familiar with with pi, right? The number, not the food.
Or, well, okay.
We're familiar with both.
Let's be honest.
Let's be honest.
We're not kidding. One more than dinner.
Yeah.
But yeah.
So if we were to represent pi as an approximate value using just the number three, right?
It's only accurate to one decimal place, right? No
matter how, no matter what precision the variable is that's actually being used to store it, right?
In that case, it's still just the one position. That's all that, that's all that it's accurate to.
Does that make sense? And I thought that's a really good way
to try to understand the difference between precision versus accuracy.
You know? So another example was like
if you had, you know,.3
versus.30, right?
You know, and you're trying to say like, oh, well, one's more precise and one's more accurate, right? Like the 0.30, you might say is more precise because it uses
more digits to represent it. But, you know, in terms of its accuracy, they're both the same
accuracy. Yep, totally. So going back, the NC sharp negative zero does equal zero.
That came back true.
Yeah, I kind of assumed it would.
I just didn't have a compiler handy.
Yep.
And then the other thing, so going back to using the floats, the doubles, those,
one thing to know is a simple operation like, you know, just adding two together or
multiplying two together, you're probably not going to get results that are that far off. It's
as you continually compute things that your margin of error is going to grow because all those,
um, you know, non-precise multiplications or computations that you're doing start to compound.
And so that's where you'll actually start to notice it.
Because I think I ran into this years ago where I was using them.
And, you know, in simple things, you never noticed it, right?
But as soon as you did something 20 times in a row, you're like, wait a second, why is that number, why is that wrong?
So you need to be aware of that. It may not crop up until you've done something multiple times before you start realizing what's actually going on. about rounding to and all of the different forms of rounding that happen because that could like
play into your um your situation you know like as as as you're running through the operations there
uh if it's on a you know a round down to zero versus a round up versus like, what was the, the, the bankers
even rounding. Yeah. The bankers around. Oh, even rounding was what they called. Yeah.
Yeah. So that one was really interesting. This actually came up on our Slack channel
months ago. It might even been a year ago now, but it was a really good thing. I want to say
it was in dev talk, have no idea who was involved at the time, but it was a really good thing. I want to say it was in dev talk, have no idea who was
involved at the time, but somebody was like, why are my numbers not rounding consistently? So you
get 1.5 and it would go to two, but then you'd have 2.5 and it would also go to two. And he's
like, why is that? And it's because there's this thing that Outlaw just referred to as banker's rounding.
It is also called even rounding.
Basically, if you're halfway in between two whole numbers, you know, one and two, it's going to round to the even number every time.
So if you're between one and two at 1.5, it's going to two.
If you're at 2.5, it's going to two.
If you're at 3.5, it's going to four.
And Outlaw even mentioned when we were talking about this the other day, we're not just talking about whole numbers.
It could be something to a decimal place, right?
But the gist of it is it's going to round the next number up or down to the closest even number.
So, yeah, if you're not aware that math.round and C Sharp does that, then you're going to be scratching your head going,
what in the world?
And,
and that's the crazy part is,
and we're going to get into this in a minute with some other things,
but every programming language implements things differently based on what
they thought at the time was the best way to do it.
Right.
So,
uh,
yeah,
pretty cool stuff to know about.
And,
and the kind of stuff that you'll spend hours going, this is wrong.
Why is it wrong?
Why is my programming language wrong?
Right?
That's ridiculous.
It's pretty cool, though.
This episode is sponsored by Coder.com.
Now, let me tell you about my new IDE.
Did I already tell you about my new 96-core development environment I have going on in the cloud here?
Let me tell you a little bit about this.
It's full on Visual Studio Code, but it's in whatever browser I choose.
So the next time you see me on the beach and you're like, hey, why is that guy paying so much attention to his phone?
It's because that's where I write all of my favorite commits.
That's awesome and not only can you write the commits but you can actually share them really easily you can just pop open the port there and also you can do the collaboration just like visual
studio code so i was able to uh i think i mentioned already uh i was able to invite outlaw into my
project where he promptly tried to wreak havoc and failed. Even if you did, it's in a
container, so it's not a big deal. You just spin that thing back up and it's going to be back to
a good state. And if you go and create your account today, you'll automatically get three
gigabytes of disk space for your container, three for your workspace, three gigabytes,
and five hours of fast time. Now, let me tell you a little bit about fast time. We told you about
those 96 cores, but what it didn't really make it clear maybe is that there's like a little button that shows up
to the left in your Visual Studio code instance in the cloud, and you click this thing and you
start running in fast mode. So I was messing around with the Gatsby site, which had a really
slow build. And as you know, I'm sure anyone who's done some sort of NPM install
and sat there waiting for it to kind of spin and do its thing,
what you can do is click this button to enable fast mode.
It instantly dumps those 96 cores and it ups your memory too.
And it just starts chewing through whatever you're trying to do.
So if you've got a CPU bound bound process like bye it's just gonna
do it it's amazing you click it on it's like the insane button in the tesla it's it's just nuts
and so you got to go try it at coder.com and it's still in alpha so alpha so things are changing
quickly and they have discord too and actually dropped a couple questions in there while i was
messing around and i was able to get feedback and some
help really quickly on how to do those things. So they'd love to hear your feedback. They'd love to
hear the things that you bump into. So you got to go give this a shot at Coder.com.
Yeah. And we forgot to say too, you can actually dynamically increase your disk space as you need
it. So if you find that you run out of that three gig and you want more, you can increase that as you need.
And this is a normal, I can't stress, this is Visual Studio code, but in your browser.
So type ahead features, all your favorite features are right there.
You want to start up your next Angular app?
No problem.
Just do it ng new my app, go into that app, ng serve.
There you're off and running withG new my app. Go into that app. NG serve there.
You're off and running with your new angular app.
Yep.
And I don't know if we mentioned this or not, but it's free to get this set up. Right.
The three gigs of space and the three gigs for your workspace and the five hours of fast time.
That's all free.
So this is something you can go sign up for and try out today and do some work in the cloud.
So again, head to coder.com, that's C-O-D-E-R.com and start your next project.
All right.
So now let's take a look at a couple of languages and we'll take a look at the kind of primitives and some of the built in stuff that they've got in there.
First, I want to kind of bring up something that you hear a lot of people talk about. And it's the notion that everything is an object in languages like C Sharp or Python or Ruby.
And that's true.
You can do even like a number 144 dot to string.
And it's an object and you can call the methods on it.
So it kind of struck me as kind of odd to think of these things being primitives when they're an object you know if
even a number is has ultimately a class behind it then how primitive is it really
well well you're talking about like in the case of c sharp where everything extends system dot
object right everything everything it's either even from there it's like value or reference
type so system the object isn't you know when you get down to enter something it's uh still like three levels deep
it's kind of crazy yep so you said isn't everything an object but then you said the answer is
uh not quite and things get really weird depending on what the the language that you're actually
looking at and so i actually made a little spreadsheet here. I'm going to flip over to now
where I took a look at those primitives that were defined in Wikipedia. I tried to match them up
with actual programming languages to kind of see how things fit with like the conceptual model of
how these things should fit. And what I found is that things are really different and really weird.
Every language had their own quirks.
I took a look at three, C Sharp, Python, and JavaScript.
And each language just had some interesting details that I thought were, you know, like pretty different at a fundamental level.
And these are things like, you know, I bounced between C Sharp and JavaScript all day.
I never really thought about it because they're kind of the edge cases.
And so for the most part, two plus two is going to to equal four and so you don't really hit this stuff too
often but when you look down kind of underneath the cover so like it's pretty complicated and so
I guess if you're doing like really math heavy stuff or doing some weird infinity dividing type
stuff like maybe you hit this stuff more than I do but I just thought it was really cool to kind
of peek behind the curtains here and see how it all works.
So I'm going to interject some thoughts on Java and some C stuff in some places because there were some interesting findings on those as well.
Yeah.
But yeah, let's take a look.
Yeah.
So the first type that Wikipedia listed was the character type.
And C Sharp has system.car.
That's no problem there.
Underneath the covers, it's actually storing it as a number.
It's basically a Unicode, which goes from like 0000 to FFFF, whatever numbers those are in hex.
So that's ultimately the biggest numbers that they can kind of fit in there and uh what i thought was particularly interesting was that if you go and you look at javascript they don't have a character
primitive the smallest thing they have is a string and like we kind of said earlier with c sharp like
we said that strings weren't primitive so how can it it be that JavaScript has a primitive, the smallest building block of string,
and C Sharp has something different, a car,
and the string isn't even considered primitive?
I'm sorry, did you say car?
Car character, dang it.
And Python is the same way.
There's no such thing as a character type in Python.
It's just string.
And a string of one character is just a string of one character.
But in C Sharp, a string is actually a collection of characters.
And I got some other kind of interesting notes here about C Sharp.
Like strings come up a little bit.
I don't want to go too deep into it, really.
You could do a whole episode.
Hey. Say what? out to C sharp and like strings come up a little bit. I didn't want to go too deep into it. Really? You could do a whole. Hey,
say what?
Well,
I was curious,
like,
you know,
I mean,
you're,
you're teasing me here with this question.
And I was like,
well,
okay.
So what was the answer?
Like,
how does JavaScript get around that?
It doesn't,
it just doesn't.
It's actually the primitive.
Yeah.
Yeah.
So there's no underlying to it other than the fact that it's string.
Now, in fairness, here's the thing to know about JavaScript as we talk about all this.
The implementations of it can be totally different based off whether they're using the V8 engine from Google or whether they're using.
I forget what some of the other ones were from Microsoft and other engines,
the underlying implementation can be doing whatever the heck it wants.
But when it all boils down to the language itself, string is actually the primitive of the language.
So, yeah.
And JavaScript does support Unicode too.
And actually, there's a funny glitch.
I think you guys have both seen it probably on Stack Overflow or stuff.
It comes up every once in a while on Reddit or wherever where JavaScript Unicode has a flaw in it, a glitch, where it starts kind of writing things sideways.
You know what I'm talking about?
They were saying the thing where the text starts and as you keep reading, it keeps descending into chaos and getting weird and text starts going sideways.
You know what I'm talking about?
No. All right. I'm going to find this you know the thing I'm talking about? No.
All right.
I didn't find this.
I know what you're talking about,
but I can't remember.
I was trying to like remember what to search for so I could put the link in
like JavaScript.
Unicode glitch is probably a good thing to look for.
Yep.
So I've got a link here as a Unicode problem from 2013.
Yep. And so if you scroll down, So I've got a link here. That was a Unicode problem from 2013.
Yep.
And so if you scroll down, hopefully there's a picture on this article.
Yep.
So if you get far down enough, it just looks wacky.
I don't even know how to read it.
But there was this famous Stack Overflow question where somebody said something about Unicode and JavaScript.
And the person started explaining why it was a problem. And as you start reading, it starts getting weirder and weirder.
And then the things start turning sideways and looking like not even what am I looking at?
Ah, and the whole thing kind of explodes.
So I will have a link to that.
I'm going to find that link while someone else is talking up here in a minute.
But yeah, I just thought that was really cool.
And there's some other interesting properties about strings and characters that I wanted to mention real quick.
Like, for instance, in JavaScript, strings are immutable, which is also what C Sharp does with their strings.
And what I mean by that, in C Sharp at least, is that every time you make an addition to a string,
like even if you lowercase it,
uppercase it, concatenate a letter, it ends up creating a whole new string at a different location in memory. The original string never gets modified. And that's why they always tell
you to use those string builders because with a string builder, it's more efficient. And so
every little change to that spring doesn't end up reallocating the whole size of string. And it just allocates a bunch of memory, kind of like an array.
And it will kind of append to that buffer.
And then when it's time to actually generate the string, it'll just do it once rather than doing it with every little change there.
Now, JavaScript doesn't have a string builder.
So you're just kind of out of luck there.
Try not to build too many strings there.
But they're immutable in the same way. So time you do it it reallocates and in c sharp there's also another kind of weird
quirk here where if strings are a reference type right so they are stored on the heap and you get
a pointer over to them but they behave a lot like a value type. So if I say, you know, string name equals Joe,
string name two equals Joe, and I check to see if name one equals name two, it's going to tell me
true. But that's not how reference types normally work. When you do equals equals on two reference
types, like two objects, it doesn't compare the properties what
it does is it uh basically looks at the actual kind of pointer to that object and says is this
the same object if it is then go ahead and return it uh return true otherwise it's false strings
don't work like that because when you create the same string, it actually points to the same spot in memory,
which is really funky to me.
A good example here of a kind of example is like the empty string.
There is only one empty string.
I get all of C sharp memory.
So when you create a new string
and you set it to empty string,
it's pointing to that memory location.
If you create a second string,
set it to empty string, just quote, quote, it's pointing to that memory location. If you create a second string, set it to empty string, just quote, quote, it's
pointing to that same spot in memory.
So now if we say, does string name
one equal name two, they're both pointing
to the same spot in memory, the answer is yes.
That's really cool. I didn't know that.
Because you're referring to an optimization that it's making.
So rather than having
a bunch of memory stored,
I mean, let's not even talk about the comparison optimization benefits you're getting by only comparing pointer addresses.
But just from like a memory space, if I had a variable that stored all of the text of the book War and Peace, and then I create a second variable, and I also want to store all of the text to War and Peace and peace and then i create a second variable and i also want
to store all of the text to war and peace the exact same text in it as an optimization it'll
just point both point to the same location and not until i need to change one then it's like okay
fine we gotta you know get new memory for this other variable wait i don't know if that so you're
saying two different variables
that have the entire story?
They wouldn't point to the same thing for that,
would they? Let's make it smaller.
I make a string one.
Let's say string
S1 equals hello world. String
S2 equals hello world.
They both point to the same block
of memory.
They're
two different pointers to the same location.
Wait, wait, wait.
We're talking even for the values of the strings?
Yeah.
Strings are going to blow your mind here, man.
Everything that you've learned about this,
about the way pointers work,
you're thinking like, well, wait, no, that's not how it works.
But for strings, it does as a matter of optimization.
So is it hashing it and throwing it into a particular spot on the heap or something so that it knows to do
it because it's not going to try and compare it and find where to put it right i don't know how
that part works uh i wouldn't be surprised if there was some sort of hash i mean like c sharp
all objects do have a get hash code type thing so it probably does do some sort of thing like that
so it knows exactly when to do it. And so it doesn't double up.
That's it.
It's not,
it's not until you decide to change it.
That's when it's like,
okay,
fine.
You know,
basically more memory,
basically imagine that like the references to that block of memory,
you know,
gets decremented,
you know,
it's now it's just the one reference and,
and the new,
the second variable gets some new block of memory,
right? With its own pointer
to that place because it's the only one
to whatever the new string is.
Now you also get
so that's a memory optimization
that you gained from it
but then you also get the comparison
operation
optimization that Joe was referring to
because now when you want to do an equality check
I don't have to go character by character through each string to see the pointer. Instead,
I take instead of what could be like an O of N operation, I take it to an O of one
by only comparing the memory address. I didn't know that. That's pretty awesome.
That's pretty wacky. I don't know if Java does that.
I think it doesn't because I've seen a colleague working in Java,
and you'd have to do the dot equals function instead of just the equal equal signs.
And that's because when you did the equal equal sign,
it would do that reference comparison and say,
nope, this is not the same object rather than comparing by the value,
which is what I expect.
So did either one of you guys
know this before we were doing these
notes? I knew this about the string,
yeah. I learned a lot about floats that I didn't
know, but the string optimization,
I did know. That's awesome.
Cool. Yeah, this is one of those things
I read about in CLR
via C Sharp, and I kind of read it and I'm like,
I don't believe it, but I'm just going to
kind of sit on it. And every couple years I go back and I'm like,
did I make that up or is that real?
And it's real. I checked it again recently.
That's awesome.
This actually came up
in a Stack Overflow, so I'll
include a link. And I think
you're right, Joe, because
I also read that book
CLR via C Sharp.
And that might be the same place that I learned of it, too.
And the Java thing makes sense because exactly what you said, the double equals is checking reference versus the value dot equals.
Yeah, so you could debate as to which one's right.
That's a weird thing.
There's actually a lot of other cool stuff going on with strings, at least in C Sharp.
There's secure strings, which are basically designed to not stick around in memory.
So if you have a password or something, you can throw it into a secure string, and it's disposable.
So it's meant to be kicked out of memory as soon as possible in case there's a core dump or something.
There's also string interpolation in C Sharp, which is actually done in a neat way, where there's a class that inherits from string, and it's got actually some special properties.
So even though it looks just kind of like a string with a funky character in front of it,
it actually is a little bit different.
It just happens to work exactly like a string everywhere because it inherits from string.
Strings are just really freaking cool if you take a deep look at them in C Sharp.
Well, I mean, they're not as cool as floats, but yeah.
Yeah.
I don't know.
They might be cooler.
Yeah.
See, man, screw data scriptures.
This is where it's at, man.
Primitives are hot.
Well, you know, I mean, I was obviously joking about the float part, but it did make me think
though, like while reading about the floats, like, yeah, you're right.
Trying to express numbers in binary sucks.
But you know what we can do?
We could represent any number we wanted to as a string.
Yep.
And guess what JavaScript can do?
Yeah.
Well, okay, fine.
But, I mean, I was actually thinking back to like the three of us I know have been in this situation where there was a, you know, the search engine that we were using at the time.
We couldn't store fractional numbers, right?
But we could store strings, for example.
I don't think it stored numbers at all now that I think about it.
No, it did.
But we could take the fractional numbers,
multiply them to be whole numbers.
Yeah, maybe that's what it was.
It was only integer based.
Right.
But at any rate, like, yeah,
that's kind of what I was thinking of.
I had memories of that situation where we had to represent decimal based numbers
as whole numbers.
And then just we knew, you know, that we were going. And then just, we knew,
you know,
that we were going to have to like,
you know,
some exponent in order to like move the decimal point.
Um,
so memories of that,
plus,
Hey,
you could just store anything as a string while going through the whole float,
uh,
thing.
Yep.
Yeah.
And,
um,
that's,
you actually reminded me of a good point.
Uh, I would just for fun i was
searching around the different libraries in c sharp but i noticed that there was one um that
added a kind of a like a library for um i forget what it was that was a long 64 where they kind of
added an approximation of a data type and they basically uh did it by keeping two long numbers
the first was to the left of this point and the second was to the right. And then if you wanted
to add or anything, the library would take care of
adding things appropriately and carrying
between the two numbers. So it's just kind of a funny way
of representing a large number. And they'll let me
do some math on it. And it had
a lot of tests, but there was a note in the readme that said
we're still kind of iffy on those square
roots. So
math is hard.
That's one of the things that was an interesting takeaway
from Java is, uh, outlaw mentioned earlier, if you just said, and I equal five, it's going to
make it a 32 bit energy, right? Well, with the 64 bit architectures now, you know, if you assign
something, you can go up to a 64 bit number, right? The interesting thing was in Java,
they didn't allow you to for, I want to say, man, where did I put the note?
I can't remember where I had it. I don't remember if it was the double or which one it was, but they don't have a 64-bit representation. It caps out at whatever the 32-bit
number is, and they don't have an implementation for the 64-bit, whereas in C Sharp they do.
And this isn't saying one's better than the other. It's just that they just never implemented it.
And there's workarounds that people have done similar to what you're talking about,
where you sort of concatenate two together, or you come up with other things to do.
There's even people that have written specifications and recommendations to the Java language to say, hey, this is how you would do it.
And they've just never implemented it.
Yeah, and actually you bring up a great segue. So for integers in C Sharp, this is the next data type, integer, I'm counting
12 different types of
integer in C Sharp.
And they range from S byte,
which is 8-bit, all
the way up to longs, which are
is that 64 bits?
Big. Is that right? I don't
know that that's 64.
It's a
lot. It's a whole lot of numbers.
Yes.
But the 12 different types are kind of weird because they're split up differently.
So there's things like byte and short and int, which are 8-bit, 16-bit, and 32-bit.
But there's also things like unsigned short and unsigned int, which give you more range in the positive direction by not letting you have
negatives.
Right.
You get that,
you get that one bit back that you're not having to assign to a sign.
Yep.
And that one bit back,
you know,
every bit you add is a lot more.
It's exponential,
right?
Like,
so yeah,
it gets much bigger.
It is.
It is literally exponential.
It is 64 bit. I went back and double it's literally exponential. It is 64-bit.
I went back and double-checked.
Okay, the long is cool.
Yeah.
So, like, the int that you have there would be the 32-bit integer.
I guess the short that you have there would be like an int 62.
I'm sorry, 62.
I'm making up my own times here. 32 bit
is what you have represented as short. I do think it's interesting that there
is not a bit. So the smallest you can go in C
sharp is just 8. Yeah, the byte.
Yeah, I've never needed one bit. I would just use a Boolean, right? Well, that's what
I was going to say. That's really what the Boole is.
Yep.
One thing I wanted to mention here, well, two things kind of.
One is kind of the point you're talking about, Alan.
Long is 64, 64 bits.
But we know that C Sharp and the CLR, it doesn't have to run on a 64-bit machine.
So what happens if you write a program that uses a long variable and you try to run that thing on a 32-bit system?
I don't know.
It still works.
And that's because the CLR is designed such that it will basically store that thing in two memory locations.
And whatever the, you know, I guess the CLR, maybe the the cls i get the common language runtime versus the
common language specification i guess would be the runtime is responsible for saying hey go grab
these two memory locations and then like let's do the math in two chunks and add it together and
store it in the same spot and that's how you can have data types that span something bigger than
the processor can handle that's cool hey I actually made a note on this one.
A long goes up to 9 quintillion.
That's crazy.
Yeah.
That's a lot.
So both positive and negative for the whole range, right?
That's for a signed long or just a long.
The unsigned long, I forget what it goes to,
but it's ridiculous.
And we mentioned that C Sharp has negative zero
and positive zero.
Unless you're
in unsigned int,
or one of the other unsigned ones, in which case
you're just going to have one zero.
One other thing I wanted to mention is the unchecked keyword,
which is the thing I don't really
think about too often. But in
C Sharp, by default, it's
going to check to see if you're going to get an overflow error.
So if you try to add something in the quintillions with something else in the quintillions,
then it's going to, it's going to stop that before it actually runs it. It's going to say,
you know, I can't do this because it's going to overflow the memory location. So I don't want to
give you essentially a wrong result as things kind of wrap over. So I'm not going to run this. But if you
want to be risky, you want to
be evil, you can actually set
unchecked above that region
and then the compiler isn't
going to, I guess it would be the
just-in-time compiler, is not going to say
it's not going to check that ahead of time. It's just going
to do the math and it's going to trust
that you know that it's not going to
overflow. So this is something that you would do for basically for efficiency like you know that
this needs to run fast and you know that the numbers that you are adding are not going to
overflow so i thought it was kind of interesting that's one of the scenes like i kind of feel like
does that ever come up ever i wonder like what not for me use cases of it though i gotta like i've got in my mind what i
think the common use cases might be which would be like around fast huh something like really fast
graphic stuff well that maybe maybe that's it i i was thinking like around like encryption related things like,
or cryptography,
you know,
where you're,
you're using like really large numbers and you can't,
you can't do normal operations like a square,
for example,
because it's already so large.
So there's other shortcuts.
There's other tricks,
math tricks to do for operations like that on large numbers so that you can get around, like overflows, for example.
Maybe that's where that comes into play.
Is there ever a time where you're just okay with overflow?
Is there ever a time?
I mean, yeah, if you're trying to hack something,
then you definitely want to overflow.
Yeah, I was going to say.
I normally think of string overflows as being the bad one.
You can kind of write something into a memory location.
And for some reason, I don't know if this is true or not,
but I had it in my mind that number overflows didn't matter.
You would just get the wrong number because it would kind of wrap.
It wouldn't actually write into memory that it shouldn't be able to to i don't know if that's true or not though so i don't know if unchecked is a
security concern or not but you should probably not do it unless for some reason you really need it
agreed now uh looking over at javascript all we we have is a number. It's called number.
And if we look ahead a little bit here at the fixed and floating points for JavaScript,
no, there's just number.
It goes from negative 2 to the 53 to 2 to the positive 53 power.
There is a negative 1.
I mean, sorry, a negative negative zero a positive zero there is also uh not nan not a
number which you'll notice is of the type number so not a number is a number well one thing to note
though while there are only numbers they have libraries built in to convert things to a float or to an integer or, or these other things.
So they have utility methods to,
to get to a particular type that you want.
And by the way,
if you ever do something like parse,
parse int or parse float,
I can't remember which one you better make sure you put the base 10 in there.
Otherwise you're going to get some really bad results.
Yeah.
But,
but yeah,
so, so while they only have number,
they have methods to force it into something
that you would use in a more strongly typed language.
I saw that was pretty cool.
You said that not a number is a number,
but I think maybe the more accurate or way to say that,
or at least maybe the more understandable way to say that is a number is used to represent not a
number. Like kind of going back to like what I was saying with the, like the float conversation
about how, you know, depending on, like, even within that data structure,
it could represent things like negative infinity, positive infinity, not a number.
So I think what he's saying is if you type in type of N-A-N, you get number.
Yep, that is the data type of not a number the n capital n lowercase a
couple n is number yeah i'm with you it was just so comical though to say that like not a number
number is a number yeah it's it's uh it's a paradox yep so the type of not a number is equal, equal, equal to the type of zero.
Right.
Or 11.
Doesn't make any sense.
Yeah. So it's kind of funny. And it's actually really funny when you look at this stuff and you think about like kind of the truthy stuff that people talk about in JavaScript.
A lot of kind of boils down to this type of thing where, you know, a lot of times people, you will see, say someone do that example where the type of dan is equal to type of you know 11 python does have in long um so you know very kind of similar i i didn't look to see if they
had an infinity oh they do uh inf that's pretty cool but you you actually have to use it in a function so it's like float of inf it's pretty
neat uh moving on to fixed points so um c sharp has decimal and that's just it right just the one
and they've got a pretty big range here i can't really say those numbers it's pretty big yeah
and it goes up to 96 bits.
And this is another one of those cases where we don't have 96-bit computers,
but that's how much it takes for each one that you allocate.
And it's actually got it separated into multiple, in this case, up to three memory locations.
And it's going to kind of combine those in order to get your actual number out of it.
And so for fixed types, you know, I have question marks here.
It looks like I meant to look that up. Does Python have fixed point type?
Well, it has integers and float, but that's it.
I have no fixed points.
All right. That's it. Oh, that's right. I have no fixed points. All right.
That's it.
Oh, that's right.
I remember this now.
There's a library that is called a decimal library that people use for doing fixed point type math.
But it's just kind of like we talked about where it stores that stuff like one number for the left and one number to the right.
And it's responsible for taking care of the,
making sure things add correctly.
So the answer is it's not a primitive.
It's a library that you can go get for the library.
It is not a primitive.
Okay.
So I'm going to put no there in the spreadsheet.
All right.
All right.
Now we're on to the floats and that's,
we talked about that quite a bit already.
C sharp has single and double.
So when you see the word float, it's actually an alias for the single data type.
That's kind of weird.
It's a weird name for it.
It's not what I would expect.
Yeah, I mean, it makes more sense if you – it doesn't make sense out of context unless you say,
you talk about double, because then you say, well, a double is double the space of the
single.
And you're like, okay, I guess I get it.
So maybe another way to say it is like, we started with the 32 bit and then went to double,
but that's not true either, right?
Because then you're ignoring a lot of computing history
where you're like, hey, wait a minute,
8-bit was a thing for quite a long time,
and then 16-bit, like, you're back in my day.
So, you know, at some point,
like Microsoft decided to, you know,
revisionist history is what you could call it.
They were just like, you know what?
Forget it.
We only ever had float.
It was a 32-bit thing.
That's the single.
And then we decided to go crazy and double that.
Like, woo-hoo.
I would love for you to do that again.
You would what?
The perfect mind, dude.
Oh, you want to hear it again?
Yeah, I do
now you made it awkward
now I'm over here blushing no
it's so good man
yeah sneak it in
so I think maybe they just
started with float and like a single double and then they got
to answer like oh crap
single and double are taken so let's do
short and long
sure yeah single and double are taken so let's do short and long sure
yeah
we forget that computers weren't
always as strong as they are now
yeah
maybe we're giving way too much
credit like somebody just like walking in
man that's a really long number
that's what we'll call it
it's hard man
it's hard
it really is And they're like, that's what we'll call it. Write that down. It's hard, man. It's hard.
It really is.
You can just imagine like someone, like the janitor walks in or something.
What's a really long number you got written on the board there?
That's it.
That's the name.
He's a genius.
Yeah.
I mean, we've been working with these systems for, you know, I don't know, 50 years, 100 years, thousands of years.
And float is the best we could come up with to describe this big complex, you know, that we talked about.
Now I understand that one.
That one makes sense to me.
Float makes sense to me now.
Yeah.
I mean, it's not a good word.
Like if someone said, hey, what about the word float for anything now?
I would say no.
What, root beer?
It's just, you know, I like words with strength.
Root beer float, that one's okay.
Now, Boolean is okay.
Boolean's a good term. Boolean's got a strong name to it, yes.
It's got strength.
It does.
Yeah, and actually, JavaScript and Python, they got nothing to say about it.
All right, you can have Boolean.
Yeah, everybody followed suit there.
Yep, nothing weird there.
Now we're about to get weird again.
So we have the reference types.
And in C Sharp, we've got int pointers and uint pointers.
And apparently, uint pointer is not a CLS thing.
So it's not common across all the different languages.
So maybe F Sharp has it. Maybe it doesn't. Maybe VB has it, maybe it doesn't.
C sharp has it, but you shouldn't use it because anything you do with C sharp, it's not going to be able
to interop with those other languages.
You should stay away from it, unless for some reason
you need it. Now, in these
other languages. JavaScript has object, but it's not considered
a primitive. So that kind of got me thinking, it's like, well, what the heck? Like, how is it not a
primitive? Like, isn't this the basic building block? Can I do it myself? And so I kind of did
some reading up on it. And basically Mozilla is kind of the authority here. So all blogs kind of lead back
to Mozilla when it comes to the types.
And they say that the object
refers to a data structure
containing data and instructions.
But they do not
consider it a primitive type unless
it's one of the other ones that we've mentioned
and one of a couple
others that we've got coming up that are unique
to JavaScript.
So, yeah, I don't really know what to say about that.
It's kind of interesting to me that JavaScript has an object
which is not a primitive,
and C Sharp has an object that is not a primitive.
However, it's got primitives that are objects.
Yeah. So int is an object
int is a primitive
object is not a primitive
yeah
yeah I got nothing there
yeah and the only thing I can think to say
there is that like you know Wikipedia
this is a general concept so this is kind of
like a you know like a flickering shadows on the cave wall kind of thing we're like this is the
concept this is what we're going for but in the real world things just don't quite shake out that
cleanly well i get it why object is not a primitive though because it's just what you said. Primitives are the most basic building blocks of what can be in things, right?
You can't break them down any further object.
You can now the C sharp thing.
I got nothing.
I don't.
Yeah.
I'm bullying is an object.
Like true is the value.
True is an object.
Yeah.
So, I mean, it's hard to say anything about that, but I get why object is not a primitive in JavaScript.
I mean, really, so what we've talked about so far in JavaScript,
really the only three that we have are string, number, and Boolean, right?
Yep.
Okay.
So far.
So far.
Yep.
You said that, did you say that int was a object though yes yeah it extends the object class
that's so that's what that's what we're getting at why it's so weird to even talk about the fact
that system.object is not a primitive but yet the primitives extend it so you've got things that
extend system.object that are primitives but but yet object itself is not a primitive.
And so it's just kind of a weird way to think about it.
I mean,
they've probably just got some weird rules in their compiler to make that.
So,
but yeah.
Yeah.
So in C sharp,
you could do like the number one,
two,
three dot two string and it's going to work.
But I thought it was a,
I thought it went back to a struck,
struck. Even if it did, that would still exist.
Everything in C Sharp extends system.object.
Yeah, including struct, right?
Oh, right.
Okay, I see the inheritance chain now.
I'm looking at it now.
Yeah, struct is a value type, which is an object.
So struct is even three levels deep.
Yeah.
It gets object value type and 32.
Yeah, it's just weird. So struct is even three levels deep. Yeah. It gets object value type and 32. Yeah.
It's,
it's just weird.
So value type is how they force it to where it's the primitive,
but yeah,
it's all mine.
I should go back and listen to our boxing and unboxing episode.
Yeah.
Especially that part of all like value types and reference types and how they
kind of end up.
And there's some interesting things about how they're assigned.
Yeah.
But I forgot all that stuff already.
Oh, this is five years ago.
Come on.
That's why we take show notes.
Python also has objects not primitive.
So now the weird ones.
Wait, now the weird ones? now the weird ones now the weird ones and i'm gonna go a little out of order here the notes uh so undefined in javascript is a type if you just do var x enter
then you have created a variable X of type undefined.
I think I remember reading something about this,
where it was talking about like the differences between the null type and the
undefined type and that they have like specifically different meanings.
Like undefined meant that the type hadn't been decided,
but null meant that the value hadn't been decided.
Something like that?
That's exactly it.
Oh, good. I solved that interview
question. Oh, yeah.
Man, I think I did it wrong. I think I totally
just said it wrong. I screwed everything up.
So when I did var x, it's null.
Right? We're going to have to pop this
open. Var x.
So I can... Okay, var x is undefined. Okay, I was right. So if I So I can, okay, VarX
is undefined. Okay, I was right. So if I say
if X equals 5, what happens?
Then in JavaScript,
then it would have to, then you're
assigning a type to it.
Okay, so that's why it doesn't
error out, right?
So now if I look at my value X, oh's really weird so i say var x it's undefined
and then if i say if x equals equals to five it coerces that x into a different type and now if i
print that x out it shows me this weird apply call.
That's really weird JavaScript stuff.
But it's no longer undefined is my point.
Just so a type change just by doing an equality comparison.
Yeah.
So like if you do var ASDF, you'll get undefined.
Right. Which is what we were saying. Yep. Yeah. So like if you do var asdf, you'll get undefined, right?
Which is what we were saying.
Yep.
Yeah, but I didn't realize though that just by doing the equality comparison in JavaScript,
it would change the type of an undefined type.
Yeah, so what if we do var x and...
Am I hearing you right?
That's what happened?
No, it did not.
So I did asdf. I defined it using var
and then I did ASDF
equal, equal, equal five
and I still got undefined for ASDF.
That's not what I'm getting.
I'm in Firefox.
Did you do an if
or did you just do the equal?
I just did equal, equal, equal.
So you're saying if ASDF
equal, equal, equal five. Now you're saying if sdf equal equal equal five now i'm
gonna do sdf no it's still undefined what the heck that's not what's happening to me it gets
signed to a really weird function so you did you did wait what are what value you're using what i
found is for whatever reason in firefox if i just did a variable like X, it already had some assignment.
So that's why I was doing ASDF, just so you know.
Yeah, I'm not getting that either, Joe.
So I do var ASDF.
Let me try a new window.
Now I have to know.
Var ASDF.
It's undefined.
Undefined undefined right and then if you do asdf equal equal equal five or even
double equal five you'll get false but if you do asdf you'll still get undefined
oh yeah i do um so yeah maybe i did something that already had a value and i kind of did the
whole prototype thing back to there i think that these debuggers already have some variables that have values in them.
And so if you're just doing a generic variable, because I tried X,
and it was coming back with something, I was like, wait a second, I didn't assign anything.
So that's why I went with a just random variable name.
Oh, okay.
Or pseudo random.
Yeah.
All right.
So undefined is a type, and null is also a type. And what were you saying about that? I said the difference there is that null is if it's typed.
Null is the absence of a value.
Actually, null is not a type. Yeah, null is a value. It is not a type.
And undefined is the absence of the type.
Correct. If you do type of null,
you get object.
If you do type of undefined, you get
undefined.
Null is actually a value.
Yeah. So if I
look at Mozilla's website, it has
null listed as a
data type. The null
type has exactly one value.
Null. So it's not
that... It's literally the
value null itself
is type. So try doing type of null.
Yeah, you get object.
You get object.
Mozilla,
you let me down.
Yeah, I got object.
So,
okay. Well, someone hopefully can leave us a comment.
Maybe.
Let us know what that's about.
Yeah, I mean, the beauty to all this stuff is because JavaScript is just so open and you can do whatever you want.
All you have to do is open up a debugger like Firefox debugger, Chrome debugger, and just start typing stuff.
And you'll find out all kinds of crazy stuff.
Oh,
value.
No represents the intentional absence,
absence of an object value.
Yep.
But they're saying it's a type or no,
it is one of JavaScript's primitive values.
Oh,
it says primitive value type here.
Yeah,
there you go.
Value.
That's funny.
Yeah.
So in the page I was looking at,
they actually mixed primitive types
and primitive values.
Yeah, that makes more sense.
And well, now they got to listen
to their data types too.
Anyway, I think we're going to have to
move on here because I'm going to spend
all day thinking about this.
Yeah, it's really weird, though.
I want to hear some more weird ones, though.
Okay.
I think we have one or two more weird ones.
Okay, while you're doing that, I'm going to get another joke ready.
How's that?
All right.
To developer, this one is thanks to, I hope I'm pronouncing this right name.
Is this name right?
Farat Ozkin?
Am I saying that right?
Oh, yeah.
Firo.
Two developers walk into a bar and order an API.
The bartender asks, which one of you is Jason?
I like it.
That's awesome.
Very nice. I told you they were gonna be dad jokes yeah i appreciate it i got my spreadsheet back up here i i guess i crashed my browser by uh
overwriting the value of x so maybe there's some modification or something
you didn't know it was so easy to destroy chrome, did you? No. Let me see here.
Yeah, X is a function.
So that's exactly what happened there.
So in Google Drive, X is defined as a function.
So it's probably like minification.
Oh, that's funny.
I'm also in Google Drive, and that's when I F12'd, and that's why.
Yeah, dude, there's all kinds of crazy functions in here.
Okay, so did you – okay, I'm sorry.
I've got to geek out on this one thing for a moment.
So when you were like brought up your dev console, then you stayed with inside of a Google doc when you did it.
Yep.
Okay.
That's why I didn't have the problem.
Cause I opened up a new tab and was playing with the console there.
And I'm like,
man,
I don't see the problem they're getting with the X already being defined.
But now I understand.
Yeah.
That's really funny.
When I did bar X, it, uh, it did go ahead and overwrite it and so it showed dull on the console but then later
after i did the if i don't understand why this happened after i did that if for some reason when
i looked at the value a second time maybe the var was out of scope i don't know what happened there
but it defaulted to the original value did you accidentally do equal instead of double equal? No, no,
no.
I didn't set it to five.
It was the,
it was the function.
This was weird function.
Yeah.
Yeah,
man,
you probably,
that's hilarious.
You overwrote something that was core to,
um,
Google docs with X,
uh,
cross my spreadsheet.
That's why I had to wait.
I went back to it.
I was like,
Hey,
wait a second.
Where'd my screen go?
Uh,
we never said that doing it live was safe.
Yeah.
Yeah, never do that.
So let that be a valuable lesson to anyone who's going to try to do live coding.
And you're like, hey, let me just bring up a JavaScript console.
Always do it in a new tab.
Yeah, open a new tab and then hit F12 or Command-Alt-I.
Yep.
So we got one more type to talk about in JavaScript.
And this is a new type in ECMA 2015.
And I have no experience with this.
So this is going to be rough.
I'm just going to try and read here.
And hopefully we'll figure something out.
This symbol is used for metaprogramming. It's a unique-ish immutable value that can be used as keys for objects that are not returned by normal looping or reflection mechanisms.
The idea here is that if you're like a framework programmer, you can do some funky stuff to tag and add additional
information to your objects and not have to worry about someone doing like basic normal javascript
looping and ended up uh ending up kind of accessing your keys and having this weird stuff show up when
they're kind of uh looping over objects wait Wait, what symbol is this? It sounds familiar.
Oh, wait, it's actually a type.
Yeah, I see it.
And Ruby has symbols, but it's a totally different thing here.
This is specifically designed for safe metaprogramming.
So if you as a framework developer want to take an object
and stuff some additional information in there on this object
to kind of tag it with
some like metadata do some other funky stuff in the framework and like use that information at
a later time then you can use these symbols as like unique identifiers it's kind of like generating
a guid wait wait a second hold on i'm not fully following this because I'm over here hacking on the console.
And if I do type of symbol, I get function.
And if I just type in symbol, it tells me it's a function.
I don't know what this function does.
Yeah.
So it's kind of quirky.
I'm not up to the date.
I am not too familiar with these details, but if you call a symbol and assign it to looks like a method,
it should generate a unique key that can be used.
This is just weird stuff,
man.
Yeah.
I,
I must,
I,
I don't know if I'm spelling it wrong or what, because it's such a complicated word to spell.
Yeah.
But like I do type of symbol and I get undefined.
Oh, hold on, hold on, hold on.
So no symbol capital S.
Yeah, but the documentation refers to lower.
So check this out. So we can do var, call it myPrivateMethod equals capital S symbol.
Yeah.
Okay.
Yep.
Now if you do type of that variable myPrivateMethod, you get symbol.
All right. of that variable my private method, you get symbol.
But if you just try to show it in the console,
it's not very interesting.
It just shows the function that you
assigned it to, which is weird.
I get why it's returning function
for the uppercase that
you did, Alan, because that's a function that's
returning the type.
Right. It gives you back a type symbol. It's really bizarre. I want to look this one up now
to see what it does because I have no idea what the use of this is.
Yeah. So the trick then is you can use this as the key in an object. So now you can say
like this, this object index.
So the square bracket, my private method.
Oh, so it's almost like a unique.
It's almost like a, almost like a good type thing for your particular object.
Yeah.
So I do this brackets, my private method.
And now I say, you know, function and I'm going to just alert.
Interesting name. Okay. Yeah. it's my private method and now i say you know function and i'm gonna just alert interesting
name okay yeah because i did var blah equal symbol capital s and then i put a in parentheses right
and or a quotation a and then afterwards i have blah and if. And if you just type in blah, it'll come back with symbol, open paren, a, close paren.
So that makes sense for what you're saying.
It's like a key that you can plug into some sort of hash.
Yeah, and it's just like any other key except the distinction is when I say, like, for var i in object, this is never going to show up.
So it's like a secret key.
It's hidden.
And the only way for you to access this is to basically know about it ahead of time
and specifically look for it.
Okay, interesting.
So if I say var my obj equal.
All right, I'm not going to do this while we're recording because it's just going to
be really boring for everybody. All right. But I see what you're saying. So if I added that as
a property on my object and I also have property first name, last name, and I did a for each,
I would see the first name and last name, but I would never see my symbol as one of the, as one of the keys that came out of it. Right. And my understanding is
that that's important for JavaScript because a lot of times you're like dealing with say like
the DOM and in HTML, you can add, uh, arbitrary elements, right? There's no like kind of
restrictions on what you can put in there. So you'll see people do stuff on like a HTML element,
like body or div or something. And they'll have like the REL attribute to kind of reference some
sort of data or maybe they'll do a data tag. There's nothing stopping you from adding any
kind of tag you want in that DOM and then referencing it via JavaScript. So if you're
a framework writer, you've got to start thinking if you're interacting with a DOM, like, well,
what's reserved? What should I hold back? Like, what do I have to tell people? Don't use these words. Don't use these attributes because I'm
using them for some sort of stuff I'm doing in my framework. So rather than saying like, okay,
here's some magic words that you have to go look in the documentation to know to avoid,
you can do this symbol trick. And you know that unless somebody is declaring the symbol in the same way that you did
that they're not going to end up exposing or bumping into your objects
to your your keys now to one point though alan you were talking about like iterating through
the properties on the object but you can get the symbols from the object.
So I'm reading another article.
They're not private.
Right.
Yeah.
They're hidden.
You have to go looking for them.
Well, I don't even know that I would say they're hidden.
They're not because I can see it.
They're not properties.
So you're not going to see them by getting the properties, but you can see them by getting the symbols.
Yeah. So yeah, hidden is not a good word, but you can see them by getting the symbol. So, yeah.
So, yeah, hidden is not a good word, but they don't show up in the loop. Like the normal like for var and like the kind of like the normal functions they usually use for like iterating or whatever.
Right.
So I'm showing right now I've done this.
Like I basically added things where I had just, you know, blah as a key and then the symbol as the value.
And then I also just went and forced in my symbol as the key.
And then I put a value on it, right?
So, your giant 34-inch monitor is being represented on my tiny little MacBook screen.
And we're translating that to listeners.
Hey, kid, you mind zooming in? two listeners. You might zoom in. But the interesting thing here is that if you dump the object,
you'll see all those.
But what Joe was saying is if you're just using a regular iterator on the
object,
it's going to ignore that symbol.
So it's interesting.
It doesn't hide it from somebody.
So people are doing framework type work.
You're still going to be able to see that,
but it will sort of safeguard you from,
from accidentally using the key.
Yeah.
It's kind of got it segmented off.
It's to its other own kind of area to help protect it.
Doesn't seem that useful to me.
So I'm sure I'm,
you know,
misunderstanding something and you can let me know in the comments.
That'd be great.
Yeah.
Pretty cool.
So yeah,
we've all learned a little something here.
Isn't that crazy?
There's no primitive type for that in Wikipedia.
Right? That's just like...
I don't know.
It's just weird. There's nothing like that
in the article about it.
This is one of those gray areas where language in the real
world is very popular.
Doing things in an incredibly different way you know traditionally think of languages in general
you know what's crazy is we did talk for over two hours about primitives yeah that's shocking
well honestly okay hey i found a good article that that might be of interest to them to you
so like you're talking about the the the, uh, use for the symbols,
but it was saying like where you might normally use a string or an integer,
like think like an enum kind of thing,
then a symbol might be of more value to you there.
So like log level debug,
log level info.
Huh?
Yeah. I'll, I'll put this article in the notes.
Excellent.
And then that way everybody can follow along.
And if you don't already know,
you can normally read the show notes within your podcast player
and follow along.
Definitely.
I say normally because, you know, not all podcast players and follow along. Definitely. I say, I say normally because,
you know,
not all podcast players are created equally.
So depending on which podcast player you use,
maybe it doesn't include it.
Yeah.
Especially the Google one.
It's really kind of,
kind of stinks.
I was hoping to try that one out,
but it really just truncates all show notes.
So I think overcast does the same.
Hmm.
Yeah.
So we,
we leave a link in there so you can click to them and to get through them.
But if you're using a really good podcast player,
you'll just be able to see it.
So I wasn't trying to pass judgment,
but now that you made it awkward,
right?
Right.
I don't know.
This thing,
this article is a,
like all this has a bunch of links and stuff that we talked about
and also all articles and everything that you can find more information about.
A few things I wanted to mention here on our way out.
You know, NC Sharper said everything was an object, but I forgot
that interfaces and pointers are not children of system dot object ah good call that's kind of a weird
distinction there and it has a couple side effects but um for the most part you don't really have to
think about it too much we were going to get some comments on that anyway so that was a nice save
right there at the end yeah hey we're about to miss my favorite. Oh, wait. Hold on. Keep going. You have more here.
Okay.
Yes.
So, and another thing I just want to, like, if we're really taking these guys being, like, the kind of the basic building blocks, like, why wouldn't it just be, like, object and pointers?
And actually in C Sharp, there's a property on all types that is called is primitive.
So you can actually do type of like int or type of my custom class and dot is primitive
and C sharp will tell you whether it considers it a primitive or not.
So I thought that was kind of interesting.
And to me, it's one of those things like the distinction is kind of weird.
Like, what does it matter if it's really a primitive or not?
And anyway, I just thought it was kind of weird. Like, what does it matter if it's really a primitive or not? And anyway, I just thought it was kind of interesting.
And did I just realize that I missed a type?
No.
Okay.
Whew.
I thought maybe I missed something.
We're starting over.
Who knew primitives could be so complicated?
Right.
Consider this a hint for next episode.
There's something interesting that you should check out.
Like I tell you what it is.
Yeah.
So anyway, I just thought it was pretty cool.
There's a, is primitive type.
And I couldn't really find a definite answer on like what kind of they used to make that distinction.
You know, like why did they say this is true and this is false?
But I think it just kind of ties to how it was originally written
and what things kind of map to whatever language they originally written in,
like C or C++, even though now it's written in C Sharp.
The C Sharp compiler is written in C Sharp.
That's so sweet.
And I mean, yeah, that's about it.
There's a lot more you can kind of dive into on all these basic primitives.
And then you can go even further.
If you start looking at like arrays in JavaScript, like it's a whole nother ocean.
It's not a primitive, it's built in, but it's just kind of cool to think that there's really so much there to know about the languages that you work with day to day.
And even though you don't necessarily need to know all the details,
there's still a lot of interesting stuff that comes out of it.
And it helps you understand some of the quirks that do exist
and kind of why they are the way that they are.
Definitely.
Hey, and now it's time for my favorite part of the show.
This is the tip of the week.
And Joe, with that, I think you have the first one here.
Yeah, so I'm kind of doing a double header here.
First, I've got to tell you about something that MadVikingGod set up.
Thank you.
If you go to codingblocks.net slash tips, that will take you to a Google form where you can add a tip, throw your name in there, however you want to be referred to. And we're going to start picking from those guys,
from those things in order to have tips.
Because I know I particularly am bad at coming up with tips.
And I see so many good ones and I lose track of them
and I'm bad about remembering who said what,
so I just don't say them.
So now what you can do instead is
if you've got a tip that you'd like to share,
you can go to codingblocks.net slash tips, pop it in there, and then I'll be scouring that for tips.
Yeah, he hasn't handed out the access to that doc yet, I will point out.
Yes.
So, only me and that fucking guy can see those results right now.
Yeah, I can't see the results.
Nope. Nope. I guess I don can't see the results. Nope.
I guess I don't get to use it.
Nope.
It's a coding block, so that is the last tips.
And I wanted to go ahead and grab one out of there.
So big thanks to BrianML02
for this
tip, which I had not considered. But if you
ever had two instances of code open,
like Visual Studio Code,
and it gets
confusing, especially with the dark
theme. I don't know what it is about it, but
I get really confused as to which one's which.
They are set up the
same way. I don't know what
it is, but for whatever reason, I always get confused
about it. What I didn't realize is that
you can change the status bar color
that's stripped down there at the
bottom. We'll have a link to that in the show notes, so you can have one being bar color that's stripped down there at the bottom.
And we'll have a link to that in the show notes.
So you can have one being that cool blue color and one being red.
So if these are things that you keep open often, then you can do that.
And that's a good way of kind of knowing the difference quickly without it being too distracting.
So are you saying that you have to like predetermine like, hey, this project is blue, this project is red?
Or are you saying that it's like as I add in the next color or as I open the next project, it'll just pick another shade?
So you can assign a color and it saves it in that.VS Code folder, like kind of at the project-ish level.
So if you've got things that you open up commonly then you can do that with the workbench color customization
very nice very cool yep and i'm sure there's a plugin that will automatically do it for you
it seems like there's a plugin for everything yeah there are plugins for everything nowadays
but most excellent all right so mine I am also borrowing from a listener who
just recently commented on episode 87. Uh, I don't even remember what that episode was about now, but
I saw the comment and went in there and replied to it. And he was saying, you guys are crazy
writing, get commands on command line, which thought I respond. We are crazy, but we are
crazy in love with those get commands on command line. It'll be respond, we are crazy, but we are crazy in love with those get
commands on command line. It'll be hard to pry those out of our dead cold hands. But he was
saying that he's actually shown other people this one called get cracking, which is G I T K R a K
E N.com. And he said that he's actually had people convert from command line to using that because
it's so good so i haven't tried it out yet being brutally honest i may at some point but i do love
my command line but if if it's good enough to convert some people then it's good enough to
recommend so um definitely go check that one out and big thanks to lee odes so appreciate that
oh and it's cross-platform by the way what's what's the uh isn't there like a
uh like an emoticon for like the skeptical face like the hmm
you know like are you really gonna get me to switch from command line like ah that's a pretty bold
statement he said it was like the visual studio code for people who like for people who are vim
people showing the visual studio code and then being like oh i get it yeah so yeah
so yeah well all right what you got that's gonna be a hard sell for me i'm not i'm not gonna lie it. Yeah. So, yeah. Well,
all right,
what you got?
That's going to be a hard sell for me.
I'm not,
I'm not going to lie.
I can't,
I can't lie to you.
Uh,
but,
but,
you know,
I appreciate the suggestion.
Um,
yeah,
so I got two.
I wanted to share.
One was that,
uh,
you know,
Michael Tippett that we referenced earlier,
he,
there was conversations that we had about before in the past. I don't remember the episode
specifically, but we talked about
having to
test for multiple
users in an environment.
And I think I'd
referenced something about
I may have even included this
like a previous tip of the week or something.
I think we have.
Because I think I remember specifically calling out how someone on a QA team showed me this trick where they were able to create a shortcut that would automatically launch into it as a different user or whatever. Um, Michael pointed out, and I don't know why we hadn't thought about this because actually I know you use this feature, Alan, but, uh, you could create multiple profiles in Chrome.
And, uh, he pointed out, you know, if you use the manage people feature inside of that, you could have those set up as different, um, accounts.
And I thought, oh yeah, that's a pretty good idea.
A good way to, good way to solve that.
So I thought it would be worth sharing that if you are in an environment where you need to test
a web app, obviously, for multiple users, then that might be a good workaround for you.
Excellent.
And then another one that I wanted to share quickly was getting started with SQL Server machine learning services.
So starting with, I want to say it was 2016, SQL Server 2016, I believe, they included support for
R. And then with 2017, they included support for python and r services where you could like and i
mean where you could like run python or r code from a sql command right um and then with the
upcoming 2019 they've even expanded on that further where um I want to say it's like Spark,
I think this is what they were adding.
Like, I don't remember.
But this link that I'm going to have in the show notes
for getting started with the machine learning services
as it relates to 2016, 2017 for Python and R
will show you what you need to do
to get your environment set up
so that you can use these new features
and run Python directly out of SQL Server. And it's pretty cool. to do to get your environment set up so that you can use these new features and you know run python
directly out of sql server and it's pretty cool like you run um you'll do a select and it'll
return back that data table as a pandas data frame for example right crazy world yeah absolutely Right? Crazy world. Yeah, absolutely. Yeah. So it's pretty neat.
So if you haven't already tried writing Python in SQL Server, here you go.
Most excellent.
All right.
Well, with that said, we hope you've enjoyed this deep dive on primitives that I don't think any one of us thought would be quite this long
or in depth but it is
and with that subscribe to us
on iTunes Stitcher and more using your favorite podcast app
if you haven't already as Joe mentioned earlier
you know we would greatly
appreciate if you left us a review, you can head to www.codingblocks.net slash review and you can
find some helpful links there. Yep. And while you're up there, check out all our show notes,
our examples, discussions, and more. And send your feedback, questions, and rants to the Slack
channel at codingblocks.slack.com.
Don't forget those tips at codingblocks.net
slash tips.
You can follow us on Twitter at codingblocks
or head over to the website
and you can find all our social links there
at the top of the page.