Tag Archives: Programming

GUID – Explained Clearly

There are multiple GUID generation algorithms, but I’ll pick one of them for concreteness, specifically the version described in this Internet draft.

The first 60 bits of the GUID encode a timestamp, the precise format of which is not important.

The next four bits are always 0001, which identify that this GUID was generated by “algorithm 1”. The version field is necessary to ensure that two GUID generation algorithms do not accidentally generate the same GUID. The algorithms are designed so that a particular algorithm doesn’t generate the same GUID twice, but without a version field, there would be no way to ensure that some other algorithm wouldn’t generate the same GUID by some systematic collision.

The next 14 bits are “emergency uniquifier bits”; we’ll look at them later, because they are the ones that fine tune the overall algorithm.

The next two bits are reserved and fixed at 01.

The last 48 bits are the unique address of the computer’s network card. If the computer does not have a network card, set the top bit and use a random number generator for the other 47. No valid network card will have the top bit set in its address, so there is no possibility that a GUID generated from a computer without a network card will accidentally collide with a GUID generated from a computer with a network card.

Once you take it apart, the bits of the GUID break down like this:

  • 60 bits of timestamp,
  • 48 bits of computer identifier,
  • 14 bits of uniquifier, and
  • six bits are fixed,

for a total of 128 bits.

The goal of this algorithm is to use the combination of time and location (“space-time coordinates” for the relativity geeks out there) as the uniqueness key. However, timekeeping is not perfect, so there’s a possibility that, for example, two GUIDs are generated in rapid succession from the same machine, so close to each other in time that the timestamp would be the same. That’s where the uniquifier comes in. When time appears to have stood still (if two requests for a GUID are made in rapid succession) or gone backward (if the system clock is set to a new time earlier than what it was), the uniquifier is incremented so that GUIDs generated from the “second time it was five o’clock” don’t collide with those generated “the first time it was five o’clock”.

Raymond Chen, devblogs.microsoft.com

Practice of Programming, From Preface

Have you ever…

  • Wasted a lot of time coding the wrong algorithm?
  • Used a data structure that was much too complicated?
  • Tested a program but missed an obvious problem?
  • Spent a day looking for a bug you should have found in five minutes?
  • Needed to make a program run three times faster and use less memory?
  • Struggled to move a program from a workstation to a PC or vice versa?
  • Tried to make a modest change in someone else’s program?
  • Rewritten a program because you couldn’t understand it?

Was it fun?

These things happen to programmers all the time. But dealing with such problems is often harder than it should be because topics like testing, debugging, portability, performance, design alternatives, and style—the practice of programming—are not usually the focus of computer science or programming courses. Most programmers learn them haphazardly as their experience grows, and a few never learn them at all.

Kernighan, Brian W.. The Practice of Programming

Is a beanbag a chair? Object Oriented Programming Dilemma.

It is hard to talk about a “chair” if nobody agrees on what a chair is. There is enough of a common example base in OO, the shape, animal, and device-driver examples; that one can start, but beyond that the nature of OO diverges from person to person.
I’ll take that challenge. Find a definition of chair. For any said definition of finite length, their is either an exception to the definition or a thing that is a chair that isn’t covered by the definition. And yet, we can still talk about chairs.

[A lot of this is because OO is a broad church embracing everyone from the prototype-based (Self, Io, JavaScript) to the class-based (Java, SmallTalk, etc ) to those who have built OO systems on top of other paradigms (CLOS, OCaml, various Scheme dialects, Python, Perl). Each of these have various flavors of usage as well so talking about OO without qualifying it usually becomes a meaningless debate about whose definition we shall use.

We can only talk about chairs if we first state that we’re only interested in wooden 4-legged chairs.]

I suppose we have beanbag chairs that are borderline “mini-couches”. But, this gets back to the need for a working classification system for OO. I don’t know if “modeling” can be separated from language or not.

Nobody Agrees On What Oo Is

Five Open-Source Projects AI Enthusiasts Might Want to Know About

TensorFlow
The Google Brain team created TensorFlow. Its underlying software powers some of the technologies that Google uses today. It translates languages, improves search engine results, recognizes pictures in Google Photos, and understands spoken words, making its machine learning (ML) capabilities genuinely awe-inspiring.

To the surprise of the tech community, Google open-sourced TensorFlow, making it available to everyone. Developers can create ML models, classes for these models, and write imperative forward passes with it, among others. TensorFlow uses Python, C++, and CUDA.

Brittany Day,  linuxsecurity.com

5 Chrome DevTools Utilities You Need to Know

3. monitor / unmonitor
If we want to track when a method is called on our page we can use the monitor() function…

Alex Ritzcovan,
https://medium.com/dailyjs/5-chrome-devtools-utilities-you-need-to-know-5bfe58c75773

the link was via npm mailing list:

We came across this handy guide from Alex Ritzcovan for the Chrome users out there, including some lesser-known Chrom DevTools utilities you might not be aware of. Here are 5 of their favorite tools provided by the DevTools team.

go to https://www.npmjs.com/ to sign up or browse.

Should Coal Miners Learn To Code? Slashdot discusses

During a campaign event on Monday, U.S. presidential candidate Joe Biden “suggested coal miners could simply learn to code to transition to ‘jobs of the future,'” reports Newsweek:
“Anybody who can go down 300 to 3,000 feet in a mine, sure in hell can learn to program as well, but we don’t think of it that way,” he said… “Anybody who can throw coal into a furnace can learn how to program for God’s sake…”

Many Twitter users criticized Biden’s comments as reductive. “Telling people to find other work without a firm plan to help them succeed will never be popular,” communications professional Frank Lutz wrote… Congressional candidate Brianna Wu tweeted that she was “glad to see the recognition that you don’t need to be in your 20s to do this as a profession,” but also called Biden’s suggestion “tone-deaf and unhelpful.”

Long-time Slashdot reader theodp notes the response this speech got from New York magazine’s Sarah Jones: “Please Stop Telling Miners To Learn To Code.” And in comments on the original submission, at least two Slashdot readers seemed to agree. “Not everyone can code and certainly not every coal miner or coal worker,” wrote Slashdot reader I75BJC. “Vastly different skills.”

Slashdot reader Iwastheone even shared a Fox News article in which rival presidential candidate Andrew Yang argued “Maybe Americans don’t all want to learn how to code… Let them do the kind of work they actually want to do, instead of saying to a group of people that you all need to become coders.”

But is there something elitist in thinking that coal miners couldn’t learn to do what coders learned to do? It seems like an interesting question for discussion

Slashdot

Object Oriented Programming – how to avoid duplication in processes that differ slightly depending on a variable

Something that comes up quite a lot in my current work is that there is a generalised process that needs to happen, but then the odd part of that process needs to happen slightly differently depending on the value of a certain variable, and I’m not quite sure what’s the most elegant way to handle this.

See a few different approaches -> stackoverflow

What is => ? What is it called and what does it do? C#.

The ‘lambda operator’. It’s read as ‘goes to’. As in, x => 2 * x is read as “x goes to 2 times x .”

A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.

To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator =>, and you put the expression or statement block on the other side. For example, the lambda expression x => x * x specifies a parameter that’s named x and returns the value of x squared.

via ms docs