-
9 votes
-
All the numbers
7 votes -
Retrohistories: The first "game over"
3 votes -
There’s new evidence for what happened to people who survived Vesuvius
8 votes -
Technology takes center court in the basketball world: The NBA elevates the game and fan experience thanks to technology and tech-savvy team owners willing to try new things.
6 votes -
THQ Nordic hosts an AMA on 8chan, releases apology two hours later
10 votes -
Researching a book before you read it?
I'm reading The Constant Gardener by John LeCarre and looking in Wikipedia for date of publication (2001) ran across the fact that it was loosely based on a true story. Now, it turns out I'm a...
I'm reading The Constant Gardener by John LeCarre and looking in Wikipedia for date of publication (2001) ran across the fact that it was loosely based on a true story. Now, it turns out I'm a frequent fan of such 'maybe almost true life books' and especially movies. Usually the extent of the 'trueness' of the movie is revealed at the end of the story.
It's often rewarding and adds to the emphasis of the story, which in itself interesting. But do any readers here avoid getting background on a story before reading? Do you think this is a type of spoiler? And does knowledge of a book being based on real events affect your opinion of the book in any way?
And finally, does anyone else often turn to Wikipedia, before or after reading a story to gain insight on its background?
7 votes -
Promoting Time Management on Mobile Devices
I had this idea for a phone that would be a feature phone, but with a Google or an Alexa powered assistant so it could have most of the functionality of an newer phone, but not as many avenues to...
I had this idea for a phone that would be a feature phone, but with a Google or an Alexa powered assistant so it could have most of the functionality of an newer phone, but not as many avenues to become lost within it. Probably wouldn't be that big of a market for it, but going off of that idea, what sort of changes would you like in phones to promote less mindless engagement sessions and allow users to better manage their own time. Is this more the responsibility of the end user to manage their own time, or can more be done at an OEM, GUI, or otherwise have these functionalities baked into the phone?
6 votes -
To build a better ballot — An interactive guide to alternative voting systems
24 votes -
What it’s like working as an Amazon Flex delivery driver
5 votes -
Keith Flint: Prodigy singer dies aged 49
14 votes -
Are certain message boards like Tildes, Reddit etc. social engineering?
The active development of Tildes and the feedback/discussions about features and mechanisms had me thinking. Is the conscious design and moderation of forums for public discourse a manner of...
The active development of Tildes and the feedback/discussions about features and mechanisms had me thinking. Is the conscious design and moderation of forums for public discourse a manner of social engineering?
I know the connotation of social engineering is usually negative, as in manipulating people for politics. But it's a double edged sword.
Most recently I was reading this feedback on removing usernames from link topics and while reading the comments I was thinking of how meta this all is. It's meta-meta-cognition in that we (well, by far the actual developers) are designing the space within which we execute our discourse and thinking. To paraphrase the above example: user identification can bias one's own impulse reaction to content, either to a beneficial or detrimental end, so how do we want this?
The moderation-influenced scenario is a bit more tricky because it can become too top-heavy, as in one prominent example many of us came from recently... But I think with a balance of direction from the overlords (jk, there is also public input as mentioned) and the chaos of natural public discourse, you could obtain an efficient environment for the exchange of ideas.
I'm not sure what my stimulating question would be for you all, so just tell me what you think.
33 votes -
Troika laundromat: A special investigation into leaked papers showing how vast sums of Russian money were channelled into western banks
10 votes -
Soy sauce is one of the most important ingredients in Japanese cooking, but chances are you've never tasted the real thing
24 votes -
‘Is my absence from social media a red flag?’
32 votes -
Why the Galaxy Fold will be a huge success even at $2,000 -- "[...] Samsung has effectively turned into the new Apple. They are the innovators. They are ahead of the game."
22 votes -
Motorola will sell its first foldable smartphone this summer
17 votes -
First confirmed Denisovan skull piece found
6 votes -
For the few who heat homes with coal, it's still king
6 votes -
Hearing hate speech primes your brain for hateful actions
11 votes -
Giving automation the power to detect crime and enforce punishment has ramifications, even for minor infractions
8 votes -
Code Quality Tip: Cyclomatic complexity in depth.
Preface Recently I briefly touched on the subject of cyclomatic complexity. This is an important concept for any programmer to understand and think about as they write their code. In order to...
Preface
Recently I briefly touched on the subject of cyclomatic complexity. This is an important concept for any programmer to understand and think about as they write their code. In order to provide a more solid understanding of the subject, however, I feel that I need to address the topic more thoroughly with a more practical example.
What is cyclomatic complexity?
The concept of "cyclomatic complexity" is simple: the more conditional branching and looping in your code, the more complex--and therefore the more difficult to maintain--that code is. We can visualize this complexity by drawing a diagram that illustrates the flow of logic in our program. For example, let's take the following toy example of a user login attempt:
<?php $login_data = getLoginCredentialsFromInput(); $login_succeeded = false; $error = ''; if(usernameExists($login_data['username'])) { $user = getUser($login_data['username']); if(!isDeleted($user)) { if(!isBanned($user)) { if(!loginRateLimitReached($user)) { if(passwordMatches($user, $login_data['password'])) { loginUser($user); $login_succeeded = true; } else { $error = getBadPasswordError(); logBadLoginAttempt(); } } else { $error = getLoginRateLimitError($user); } } else { $error = getUserBannedError($user); } } else { $error = getUserDeletedError($user); } } else { $error = getBadUsernameError($login_data['username']); } if($login_succeeded) { sendSuccessResponse(); } else { sendErrorResponse($error); } ?>
A diagram for this logic might look something like this:
+-----------------+ | | | Program Start | | | +--------+--------+ | | v +--------+--------+ +-----------------+ | | | | | Username +--->+ Set Error +--+ | Exists? | No | | | | | +-----------------+ | +--------+--------+ | | | Yes | | v | +--------+--------+ +-----------------+ | | | | | | | User Deleted? +--->+ Set Error +->+ | | Yes| | | +--------+--------+ +-----------------+ | | | No | | v | +--------+--------+ +-----------------+ | | | | | | | User Banned? +--->+ Set Error +->+ | | Yes| | | +--------+--------+ +-----------------+ | | | No | | v | +--------+--------+ +-----------------+ | | | | | | | Login Rate +--->+ Set Error +->+ | Limit Reached? | Yes| | | | | +-----------------+ | +--------+--------+ | | | No | | v | +--------+--------+ +-----------------+ | | | | | | |Password Matches?+--->+ Set Error +->+ | | No | | | +--------+--------+ +-----------------+ | | | Yes | | v | +--------+--------+ +----------+ | | | | | | | Login User +--->+ Converge +<--------+ | | | | +-----------------+ +---+------+ | | +-----------------+ | v +--------+--------+ | | | Succeeded? +-------------+ | | No | +--------+--------+ | | | Yes | | v v +--------+--------+ +--------+--------+ | | | | | Send Success | | Send Error | | Message | | Message | | | | | +-----------------+ +-----------------+
It's important to note that between nodes in this directed graph, you can find certain enclosed regions being formed. Specifically, each conditional branch that converges back into the main line of execution generates an additional region. The number of these distinct enclosed regions is directly proportional to the level of cyclomatic complexity of the system--that is, more regions means more complicated code.
Clocking out early.
There's an important piece of information I noted when describing the above example:
. . . each conditional branch that converges back into the main line of execution generates an additional region.
The above example is made complex largely due to an attempt to create a single exit point at the end of the program logic, causing these conditional branches to converge and thus generate the additional enclosed regions within our diagram.
But what if we stopped trying to converge back into the main line of execution? What if, instead, we decided to interrupt the program execution as soon as we encountered an error? Our code might look something like this:
<?php $login_data = getLoginCredentialsFromInput(); if(!usernameExists($login_data['username'])) { sendErrorResponse(getBadUsernameError($login_data['username'])); return; } $user = getUser($login_data['username']); if(isDeleted($user)) { sendErrorResponse(getUserDeletedError($user)); return; } if(isBanned($user)) { sendErrorResponse(getUserBannedError($user)); return; } if(loginRateLimitReached($user)) { logBadLoginAttempt($user); sendErrorResponse(getLoginRateLimitError($user)); return; } if(!passwordMatches($user, $login_data['password'])) { logBadLoginAttempt($user); sendErrorResponse(getBadPasswordError()); return; } loginUser($user); sendSuccessResponse(); ?>
Before we've even constructed a diagram for this logic, we can already see just how much simpler this logic is. We don't need to traverse a tree of if statements to determine which error message has priority to be sent out, we don't need to attempt to follow indentation levels, and our behavior on success is right at the very end and at the lowest level of indentation, where it's easily and obviously located at a glance.
Now, however, let's verify this reduction in complexity by examining the associated diagram:
+-----------------+ | | | Program Start | | | +--------+--------+ | | v +--------+--------+ +-----------------+ | | | | | Username +--->+ Send Error | | Exists? | No | Message | | | | | +--------+--------+ +-----------------+ | Yes | v +--------+--------+ +-----------------+ | | | | | User Deleted? +--->+ Send Error | | | Yes| Message | +--------+--------+ | | | +-----------------+ No | v +--------+--------+ +-----------------+ | | | | | User Banned? +--->+ Send Error | | | Yes| Message | +--------+--------+ | | | +-----------------+ No | v +--------+--------+ +-----------------+ | | | | | Login Rate +--->+ Send Error | | Limit Reached? | Yes| Message | | | | | +--------+--------+ +-----------------+ | No | v +--------+--------+ +-----------------+ | | | | |Password Matches?+--->+ Send Error | | | No | Message | +--------+--------+ | | | +-----------------+ Yes | v +--------+--------+ | | | Login User | | | +--------+--------+ | | v +--------+--------+ | | | Send Success | | Message | | | +-----------------+
Something should immediately stand out here: there are no enclosed regions in this diagram! Furthermore, even our new diagram is much simpler to follow than the old one was.
Reality is rarely simple.
The above is a really forgiving example. It has no loops, and loops are going to create enclosed regions that can't be broken apart so easily; it has no conditional branches that are so tightly coupled with the main path of execution that they can't be broken up; and the scope of functionality and side effects are minimal. Sometimes you can't break those regions up. So what do we do when we inevitably encounter these cases?
High cyclomatic complexity in your program as a whole is inevitable for sufficiently large projects, especially in a production environment, and your efforts to reduce it can only go so far. In fact, I don't recommend trying to remove all or even most instances of cyclomatic complexity at all--instead, you should just be keeping the concept in mind to determine whether or not a function, method, class, module, or other component of your system is accumulating technical debt and therefore in need of refactoring.
At this point, astute readers might ask, "How does refactoring help if the cyclomatic complexity doesn't actually go away?", and this is a valid concern. The answer to that is simple, however: we're hiding complexity behind abstractions.
To test this, let's forget about cyclomatic complexity for a moment and instead focus on simplifying the refactored version of our toy example using abstraction:
<?php function handleLoginAttempt($login_data) { if(!usernameExists($login_data['username'])) { sendErrorResponse(getBadUsernameError($login_data['username'])); return; } $user = getUser($login_data['username']); if(isDeleted($user)) { sendErrorResponse(getUserDeletedError($user)); return; } if(isBanned($user)) { sendErrorResponse(getUserBannedError($user)); return; } if(loginRateLimitReached($user)) { logBadLoginAttempt($user); sendErrorResponse(getLoginRateLimitError($user)); return; } if(!passwordMatches($user, $login_data['password'])) { logBadLoginAttempt($user); sendErrorResponse(getBadPasswordError()); return; } loginUser($user); sendSuccessResponse(); } $login_data = getLoginCredentialsFromInput(); handleLoginAttempt($login_data); ?>
The code above is functionally identical to our refactored example from earlier, but has an additional abstraction via a function. Now we can diagram this higher-level abstraction as follows:
+-----------------+ | | | Program Start | | | +--------+--------+ | | v +--------+--------+ | | | Attempt Login | | | +-----------------+
This is, of course, a pretty extreme example, but this is how we handle thinking about complex program logic. We abstract it down to the barest basics so that we can visualize, in its simplest form, what the program is supposed to do. We don't actually care about the implementation unless we're digging into that specific part of the system, because otherwise we would be so bogged down by the details that we wouldn't be able to reason about what our program is supposed to do.
Likewise, we can use these abstractions to hide away the cyclomatic complexity underlying different components of our software. This keeps everything clean and clutter-free in our head. And the more we do to keep our smaller components simple and easy to think about, the easier the larger components are to deal with, no matter how much cyclomatic complexity all of those components share as a collective.
Final Thoughts
Cyclomatic complexity isn't a bad thing to have in your code. The concept itself is only intended to be used as one of many tools to assess when your code is accumulating too much technical debt. It's a warning sign that you may need to change something, nothing more. But it's an incredibly useful tool to have available to you and you should get comfortable using it.
As a general rule of thumb, you can usually just take a glance at your code and assess whether or not there's too much cyclomatic complexity in a component by looking for either of the following:
- Too many loops and/or conditional statements nested within each other, i.e. you have a lot of indentation.
- Many loops in the same function/method.
It's not a perfect rule of thumb, but it's useful for at least 90% of your development needs, and there will inevitably be cases where you will prefer to accept some greater cyclomatic complexity because there is some benefit that makes it a better trade-off. Making that judgment is up to you as a developer.
As always, I'm more than willing to listen to feedback and answer any questions!
25 votes -
Apollo 11 is phenomenal, and gave me an existential crisis
Apollo 11 is a limited IMAX only engagement, at least for now, and I don't know how long it'll be in theaters. But while it is, I implore everyone to go see it.This movie left me speechless, and...
Apollo 11 is a limited IMAX only engagement, at least for now, and I don't know how long it'll be in theaters. But while it is, I implore everyone to go see it.This movie left me speechless, and not just in the sense of the footage being so incredible as to leave me without words, though that's certainly a factor. It's restored footage and audio of the Apollo 11 mission, for anyone that doesn't know, and it covers the launch, moon landing, and re-entry.
It's so easy for historical events to be looked back on and be seen as just that: events. Like a natural disaster or the existence of a waterfall or a canyon, so many battles, inventions, and human triumphs are stripped of humanity, remembered only as things that happened, not things people did. Apollo 11 has staggering to witness footage, yes, but it weaves that footage together with the human moments wonderfully. The scenes of the launch countdown or the lander making its descent are intercut and splitscreened with the footage of the NASA control centers, with names of all the teams, as audio of their conversations with the astronauts and recaps of what has happened and is going to play over the incredibly restored launch footage. Cuts to the crowd overlooking the Apollo 11 launch are also common in the beginning.
This is not an educational video, one to be seen for great understanding of the finer details of the mission. Apollo 11 instead acts as history in motion, with a perspective to the individuals and the event simultaneously. It's about the people that accomplished the amazing things you see. A display of the triumph of human spirit over the perceived rules of the world and the desire for understanding out world and breaking the limits that we thought were imposed on us. And yet, we as the viewers have a perspective that the people who actually accomplished the great things we see never did. The splitscreening helps to assign human beings to the awe inspiring footage in front of the viewer, yes, but at the same time it offers 2 entirely separated perspectives framed as one, one that the human beings being assigned to the footage never truly experienced in the moment. We have an intimate view of the control center with a simultaneous omnipotent-esque view of the mission in all of its glory. The viewer as the omnipotent being is true of most films to some degree, but the way in which the movie frames its central event, small and big at the same time, really highlights an omnipresent view that even those who lived through the launch never experienced in real time. It's a film of contrast between the individuals and the accomplishment of the collective, but in its control center voiceovers and constant splitscreens, it's really a movie that bridges the two contrasts.
Basically, I loved it in ways that, despite my extensive best efforts, I find difficult to describe. This line sounds corny, I know, but you owe it to yourself to see it on the biggest screen that you can, and I implore everyone to try to make time for it and find a true IMAX showing, if possible. The visuals alone may not have been the biggest thing that awed me, but they were certainly a huge part of it. And for anyone that's also seen it, what'd you think? I'd love to see other perspectives on this doc.
11 votes -
A sports hijab has France debating the Muslim veil, again
10 votes -
The life of a comment moderator for a right-wing website
27 votes -
Feature suggestion: Highlighted text in comment automatically creates quote when you respond to that comment
I'm fairly sure it's either a Reddit or RES feature, but whenever I select text in a comment and then click Reply, it'll copy that text to the comment box and add a > in front so it'll turn into a...
I'm fairly sure it's either a Reddit or RES feature, but whenever I select text in a comment and then click Reply, it'll copy that text to the comment box and add a > in front so it'll turn into a quote. It makes it a little quicker to respond to a specific part of someone's message.
I'm no IT bird and as such I don't know if this is something that can be implemented easily(if at all). It'd also require more JS, not sure if that's an issue as well.
In any case, let me know what you think.
Edit: I'd like to suggest something else, should I make a secondary post or append it to this one? I'd like to avoid cluttering up the front page.
37 votes -
The last generation
7 votes -
Momo Challenge, memes, and "Secure, Contain, Protect" (SCP)
First, I apologize if this is inappropriate. I wouldn't be surprised if some folks here saw my mention of the "Momo Challenge" and roll their eyes, but after my brother asked me about it, I looked...
First, I apologize if this is inappropriate.
I wouldn't be surprised if some folks here saw my mention of the "Momo Challenge" and roll their eyes, but after my brother asked me about it, I looked it up last night, and found some interesting stuff happening around it. I guess it's going through a second iteration right now, with supposed images of "Momo," a sculpture of a Japanese witch, and a voice saying to do really graphic stuff. The previous iteration was supposedly messaging a number via WhatsApp, and getting challenges, and threats that if you tell your parents (it's supposedly targeting kids), Momo will get you. The Guardian has a nice write up about the current issue with a picture, you have been warned if you scare easily. Now, she'll tell you to do stuff in a manipulated video. There's even themomochallenge.tk (also spooky if you're sensitive to uncanny sort of stuff like I am), which seems to exist as a way to fluff the story, and asks for what I assume is a requested cryptocurrency transaction (how a kid is going to get crypto to send, I don't know). I may seem like I'm writing something absurd, but this is not in ~creative on purpose, and I feel the propagation of this sort of thing speaks to several problems that may or may not be solvable.
My fascination is with the spread of the idea, and its possible effects. As somebody who occasionally reads the SCP Wiki (not to do with Secure Copy Protocol), I noticed something interesting in the rapid spread of this meme, and am sure sociologists would describe it differently. It behaves (insofar as a meme is an entity with a life or intelligence) in a way SCP would describe as "infohazardous" or "cognitohazardous." They don't mean the same thing: The information is a hazard (infohazard) because you know have this bomb sitting in your lap. You can warn people, but they may go out, see the supposed deaths, and believe it, or you can get a chain of people warning others. In either case, you pass the ball. The meme grows.
It is cognitohazardous for the reason that this hoax, by design, preys on fear. Just typing this, the face is burned into my vision (again, I'm sensitive), I'm home alone, and becoming rather shaky as I jump to look behind me at random noises. The chosen image of the sculpture was selected for this reason, it is deeply unsettling, shakes your rational mind, and you're potentially induced into believing it. I have, in a way, fallen victim to this.
The question comes, going back to my SCP reference: How can this be contained? I'm not looking to start a task force, or enlist people's help, but this is obviously not the first time this has happened with things from Satanic rituals and 2016(?)'s Blue Whale. My mom got swept up by the Satanic thing in the 90s, I watched a video about satanic sacrifices before Halloween 1997, I think, that she got from her church, so I have some experience from the other side. My primary concern is not that children are being compelled to kill themselves, but that the ensuing panic moral panic alone can cause psychological trauma and rampant misinformation. Is it possible to convince believers that something like this isn't real before copycat stuff comes out?
26 votes -
Who are your 5 favorite anime characters of all time?
Mine are: Goku (as a child) Vegeta (DBZ) Light Yagami (Death Note) Edward Elric (Fullmetal Alchemist) Jotaro Kujo (Jojo)
9 votes -
What was your fondest memories of anime?
We all have our fair share of precious moments during our time as weebs. Mine was watching the final episode of Gurren Lagann when I was 10. Back then kid me was really hyped at the sheer scope of...
We all have our fair share of precious moments during our time as weebs.
Mine was watching the final episode of Gurren Lagann when I was 10. Back then kid me was really hyped at the sheer scope of the final battle. I watched it in dub but the impact of it solidified my fanaticism in anime.
15 votes -
Workism is making Americans miserable
42 votes -
'Sex Education' renewed for season 2 at Netflix
7 votes -
Memes are our generation's protest art
13 votes -
Pakistan opens public school for transgender students
11 votes -
Lyft files first for IPO in litmus test for the industry
16 votes -
Dredg - Scissor Lock (2002)
4 votes -
Brain-imaging modern people making Stone Age tools hints at evolution of human intelligence
6 votes -
You Don’t Need All That Complex/Expensive/Distracting Infrastructure
14 votes -
Status as a Service
3 votes -
MISTER FPGA: The Future of Retro Game Emulation and Preservation?
9 votes -
My new croissant machine can do things I can't
5 votes -
Where does London stop? | Unfinished London
12 votes -
The darkness
30 votes -
Getting rich teaching Hong Kong's kids
4 votes -
This Week's Releases 01/03 - Solange, Pond, 2-Chainz and more.
Releases of the week 23/02/2019 - 01/03/2019 Featured Release Solange - When I Get Home (Neo-Soul, Alternative R&B) Solange has unveiled her new album, When I Get Home. Spanning 19 tracks, it...
Releases of the week 23/02/2019 - 01/03/2019
Featured Release
Solange - When I Get Home (Neo-Soul, Alternative R&B)
Solange has unveiled her new album, When I Get Home. Spanning 19 tracks, it marks Solange’s fourth album to date and serves as the follow-up to her 2016 opus, A Seat at the Table.
When I Get Home was written, performed, and executive produced by Solange herself, but she was hardly in the studio. Among the album’s many contributors were Earl Sweatshirt, Panda Bear, Tyler the Creator, Blood Orange’s Dev Hynes, Sampha, Pharrell Williams, Gucci Mane, Playboi Carti, Raphael Saadiq, Metro Boomin, The-Dream, Cassie, Abra, and The Internet’s Steve Lacy.
“Y’all! I’m filled w so much joy right now!!! Wow! I can’t thank y’all enough for this moment and for all the feelings i feel in my body!” Solange wrote in a tweet. “I’m bringing home w me everywhere I go yalll and I ain’t running from shit no more. Your love lifts me up so high. Thank you!”Other Notable Relases
Pond - Tasmania (Neo-Psychedelia, Psychedelic Pop)
2 Chainz - Rap or Go to the League (Trap Rap, Southern Hip Hop)
Sun Kil Moon - I Also Want To Die In New Orleans (Contemporary Folk, Spoken Word)
T-Pain - 1UP (Alternative R&B, Trap Rap)
Feel free to discuss or feature any and all other releases in the comments below
Discussion Points
Have you listened to any of these releases?
What are your thoughts?
What are you looking forward to listen to?
What have you enjoyed from these artists in the past?// All feedback on this format welcome.
7 votes -
Robert Smith, Toti Panzanelli, et al. - Not in Love
4 votes -
Hindu monastic order is reclaiming transgender people’s status in Indian society
9 votes -
What is your first-hand experience with the "Dunning–Kruger effect"?
In the field of psychology, the Dunning–Kruger effect is a cognitive bias in which people of low ability have illusory superiority and mistakenly assess their cognitive ability as greater than it...
In the field of psychology, the Dunning–Kruger effect is a cognitive bias in which people of low ability have illusory superiority and mistakenly assess their cognitive ability as greater than it is. The cognitive bias of illusory superiority comes from the inability of low-ability people to recognize their lack of ability. Without the self-awareness of metacognition, low-ability people cannot objectively evaluate their competence or incompetence. (Wikipedia)
Some of my fellow programmers seem to think the world turns around their knowledge as if there was no valid reasoning whatsoever beyond math and computer science. They seem to think logic (a tool with multiple uses which exists since at least 380 BC) is merely an attribute of computer science. It's not uncommon for them to think they can understand the intricacies of every phenomenon under the sun.
I have to control myself to avoid countering each of their flawed arguments. To my own detriment, I'm not always able to do so. I feel surrounded by arrogance and cognitive bias, and have to silence my better judgment in order to avoid constant conflict.
To be clear, I'm not looking for advice, as I already know the "solution", which is no solution. You can't use reason to fight something that is not motivated by reason. I'm posting to know your stories and maybe find some solace in the knowledge that I'm not alone.
Have you ever had to deal directly with people who grossly inflate their own competence, possibly stretching it to an unrelated field? if so, what's your story?
20 votes -
Inside Facebook’s war on hate speech: An exclusive embed with Facebook’s shadow government
14 votes -
Battles - Ddiamondd (2007)
9 votes