CodeSOD: Switching Daily

A not uncommon pattern is to use a dictionary, or array as a lookup table in place of a switch or conditional. In some languages, like Python, there is no switch statement, and dictionaries are the main way to imitate that behavior.

In languages like JavaScript, where the line between objects and dictionaries is blurred to the point of non-existence, it’s a common approach. A lot of switch statements can be converted to an object literal with functions as its values, e.g.:

var myVal = getMyVal();
let lookup = {'foo': doFoo, 'bar': doBar};
lookup[myVal]();

Cassi had a co-worker who was at least peripherally aware of this technique. They might have heard about it, and maybe they saw it used once, from a distance, on a foggy day and their glasses were covered with rain and they also weren’t actually paying attention.

When they needed to convert a day, represented as a number from 1–7, into a day-as-a-string, they wrote some code which looks like this:

	/**
	 * Converts the given weekday number (Sunday = 1) to the weekday name
	 * @param {number} dayNum
	 * @return {string}
	 */
	$company.time.dayNumToDayName = function(dayNum) {
		return /** @type {string} */ ($company.misc.shortSwitch(dayNum, [
			[1, 'Sunday'],
			[2, 'Monday'],
			[3, 'Tuesday'],
			[4, 'Wednesday'],
			[5, 'Thursday'],
			[6, 'Friday'],
			[7, 'Saturday']
		]));
	};

We’ll get to shortSwitch in a moment, but let’s just look at how they designed their lookup table. I’d say that they’ve reinvented the dictionary, in that these are clearly key/value pairs, but since the keys are indexes, what they’ve really done is reinvented the array so that they can have arrays which start at one.

Yes, it would be simpler to have just done return listOfDayNames[dayNum - 1], but with some bounds checking. Maybe that’s what $company.misc.shortSwitch does, somehow?

	/**
	 * Simulates a switch statement (with fewer lines of code) by looping through
	 * the given cases and returning the value of the matching case.
	 * @template C
	 * @template V
	 * @param {C} switchVal - the value to switch on
	 * @param {Array<(C|V)>!} cases - an array of [case, value] pairs
         * @return V
	 */
	$company.misc.shortSwitch = function (switchVal, cases) {
		for(var i = 0; i < cases.length; i++) {
			if(cases[i][0] === switchVal) return cases[i][1];
		}
	};

Simulates a switch statement (with fewer lines of code), they say. In reality, they’ve simulated a lookup table with more lines of code, and as a bonus, this needs to inspect every element (until it finds a match), versus a lookup table which only needs to directly access the match.

Whether or not Cassi fixes the dayNumToDayName method, that’s a small thing. As you can imagine, when someone writes a hammer like shortSwitch, that’s gonna be used to turn everything into a nail. shortSwitch is called all over the codebase.

I can only assume/hope that Cassi will be switching jobs, shortly.

//thedailywtf.com/images/highlight/highlight.pack.js
hljs.initHighlightingOnLoad();

[Advertisement]
Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps – Think Raygun! Installs in minutes. Learn more.


CodeSOD: Switching Daily syndicated from https://koresol.wordpress.com/

CodeSOD: Inching Along

"Procedures should be as small as possible," is good advice. Like any good advice, you can take it too far.

Mike recently was asked to upgrade a SQL Sever 2000 database to SQL Server 2016. Since this was an upgrade, Mike wasn't supposed to make any changes beyond the necessary changes to make the upgrade work. Still, when he found a bunch of methods with the same basic naming pattern, he had to investigate.

CREATE PROCEDURE [dbo].[sp_inchworm_1wk] AS BEGIN INSERT INTO #inchworm_1wk(…) -- seven records get inserted EXEC sp_inchworm_1wk_a1 @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a1] AS BEGIN INSERT INTO #inchworm_1wk_a1 SELECT * FROM #inchworm_1wk; EXEC sp_inchworm_1wk_a2 @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a2] AS BEGIN INSERT INTO #inchworm_1wk_a2 SELECT * FROM #inchworm_1wk_a1; EXEC sp_inchworm_1wk_a3 @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a3] AS BEGIN INSERT INTO #inchworm_1wk_a3 SELECT * FROM #inchworm_1wk_a2; IF @vendor_flag = 1 EXEC sp_inchworm_1wk_a4a @fiscal_wk_end_date,@vendor_flag ELSE EXEC sp_inchworm_1wk_a4b @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a4a] AS BEGIN INSERT INTO #inchworm_1wk_a4a SELECT * FROM #inchworm_1wk_a3; EXEC sp_inchworm_1wk_a5a @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a4b] AS BEGIN INSERT INTO #inchworm_1wk_a4b SELECT * FROM #inchworm_1wk_a3; EXEC sp_inchworm_1wk_a5b @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a5a] (@fiscal_wk_end_date SMALLDATETIME ,@vendor_flag TINYINT) AS BEGIN INSERT INTO #inchworm_1wk_a5a SELECT * FROM #inchworm_1wk_a4a; EXEC sp_inchworm_1wk_a6 @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a5b] (@fiscal_wk_end_date SMALLDATETIME ,@vendor_flag TINYINT) AS BEGIN INSERT INTO #inchworm_1wk_a5b SELECT * FROM #inchworm_1wk_a4b; EXEC sp_inchworm_1wk_a6 @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a6] (@fiscal_wk_end_date SMALLDATETIME ,@vendor_flag TINYINT) AS BEGIN INSERT INTO #inchworm_1wk_a6 SELECT * FROM #inchworm_1wk_a5a; INSERT INTO #inchworm_1wk_a6 SELECT * FROM #inchworm_1wk_a5b; IF @vendor_flag = 1 EXEC sp_inchworm_1wk_a7a @fiscal_wk_end_date,@vendor_flag ELSE EXEC sp_inchworm_1wk_a7b @fiscal_wk_end_date,@vendor_flag END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a7a] (@fiscal_wk_end_date SMALLDATETIME ,@vendor_flag TINYINT) AS BEGIN INSERT INTO #inchworm_1wk_a7a SELECT * FROM #inchworm_1wk_a6; EXEC sp_inchworm_1wk_a8 END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a7b] (@fiscal_wk_end_date SMALLDATETIME ,@vendor_flag TINYINT) AS BEGIN INSERT INTO #inchworm_1wk_a7b SELECT * FROM #inchworm_1wk_a6; EXEC sp_inchworm_1wk_a8 END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a8] AS BEGIN INSERT INTO #inchworm_1wk_a8 SELECT * FROM #inchworm_1wk_a7a; INSERT INTO #inchworm_1wk_a8 SELECT * FROM #inchworm_1wk_a7b; EXEC sp_inchworm_1wk_a9 END GO CREATE PROCEDURE [dbo].[sp_inchworm_1wk_a9] AS BEGIN -- returns final data set END GO

The code worked, in both SQL Server 2000 and 2016, so Mike wasn't allowed to change it. It's on a list of things to fix, someday in the future, as part of paying down technical debt. You could say that they'll keep inching towards fixing this, and maybe they'll get there eventually.

//thedailywtf.com/images/highlight/highlight.pack.js
hljs.initHighlightingOnLoad();

[Advertisement]
Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps – Think Raygun! Installs in minutes. Learn more.


CodeSOD: Inching Along syndicated from https://koresol.wordpress.com/

Talk: How To Design For What’s Next, Executive Director, Experience Design AKQA | David Vogel

David Vogel is Executive Director, Experience Design at AKQA (Europe) where he creates delightful products and experiences that add value for consumers.At…
Talk: How To Design For What’s Next, Executive Director, Experience Design AKQA | David Vogel syndicated from https://koresol.wordpress.com/

Announcing Docker Enterprise 3.0: Delivering High-Velocity Application Innovation

Today at DockerCon, we’re excited to announce Docker Enterprise 3.0 – the only desktop-to-cloud enterprise container platform enabling organizations to build and share any application and securely run them anywhere – from hybrid cloud to the edge.

With Docker Enterprise 3.0, developers can rapidly build multi-service container-based applications right from their desktop and package them in a standardized format that can be shared seamlessly and run anywhere. In addition, Docker Enterprise 3.0 expands its container platform leadership position with the introduction of new capabilities for automated lifecycle management and enhanced security.

Here are some of the highlights that you can look forward to in Docker Enterprise 3.0.

Accelerated application delivery

Enterprises are looking for ways to quickly adapt to new competitive challenges and changing customer requirements through the introduction of new applications. Docker Enterprise 3.0 introduces a number of capabilities that help organizations accelerate application delivery.

Docker Desktop Enterprise

Docker Desktop Enterprise is a new developer tool that extends the Docker Enterprise Platform to developers’ desktops, improving developer productivity while accelerating time-to-market for new applications.

  • Application Designer interface: template-based workflows for creating containerized applications – no Docker CLI commands are required to get started
  • Configurable version packs: instantly replicate production environment configurations on the local desktop to avoid “works on my machine” friction
  • Centrally managed and secured: Packaged as a standard MSI (Win) and PKG (Mac) distribution files that work with existing endpoint management tools
  • Automation and template-driven generation of IT-approved Dockerfiles, Docker Compose files, and CI pipelines boosts developer productivity

Docker Application

Docker Application is a new set of tooling that enables end-to-end application consistency and scalability from developers to operators. It allows users to manage complex applications as simply as individual containers, with tools to build, push, and deploy multi-container applications as self-contained objects.

  • Based on open standard CNAB: Docker Application is based on CNAB – a joint collaboration of Docker, Microsoft, Bitnami, HashiCorp and CodeFresh
  • Docker Application Template: Make sharing and standardization of applications simpler and more scalable by templatizing applications and their deployment parameters.
  • Docker Assemble: Easily generate Dockerfiles and the associated files for common application frameworks without expert Docker knowledge. Get development up to speed faster by letting developers focus on their business logic.

Docker Kubernetes Service (DKS)

Docker Enterprise 3.0 introduces Docker Kubernetes Service –  the only offering that integrates Kubernetes from the developer desktop to production servers. This will make Kubernetes easier, more secure, and more accessible to the entire organization.

  • Shipping with Kubernetes 1.14: DKS includes the latest release of Kubernetes, including full support for Container Storage Interface (CSI).
  • Single platform for developers and operators: DKS is the only Kubernetes offering that provides consistency across the full development lifecycle. Through the use of version packs, Kubernetes developer environments stay in sync with production environments for a complete, seamless Kubernetes experience.

Automated deployment of containers on your choice of infrastructure

Docker Enterprise 3.0 includes new lifecycle automation tools for day 1 and day 2 operations, helping customers accelerate and expand the deployment of containers on their choice of infrastructure.

  • Transparent cluster upgrades: Apply blue-green upgrades to your container infrastructure to reduce and eliminate application impact. Control your infra software lifecycle with more control and less risk.
  • Docker Cluster: Automate and simplify cluster deployments no matter which environment. Whether AWS, Azure, or VMware, Docker Enterprise deploys in highly customizable ways that allow operators to scale the number of clusters and different environments that they support.

Enhanced security

Docker Enterprise 3.0 includes additional security enhancements that expand the set of applications that can be addressed with Docker Enterprise and the types of organizations that can deploy it.

  • Group Managed Service Accounts (gMSA) for Swarm: Support for gMSA brings Docker Enterprise to a wider set of Windows Server applications that require Active Directory authentication. Swarm allows the creation of credential specs with Docker Configs to bring ease of use and automation to gMSA.
  • PKI Certificate-Based Authentication: In addition to LDAP/AD integration and SAML 2.0 support, highly regulated organizations can now use PKI authentication to control access to Docker Enterprise.

How to Get Started

[Tweet “Big News! Introducing Docker Enterprise 3.0 – delivering high-velocity innovation from the desktop to the cloud”]

The post Announcing Docker Enterprise 3.0: Delivering High-Velocity Application Innovation appeared first on Docker Blog.

Announcing Docker Enterprise 3.0: Delivering High-Velocity Application Innovation syndicated from https://koresol.wordpress.com/

2019 Customer Innovation awards: 6 Stories of Transformation in the Enterprise

We are thrilled to honor six of our enterprise customers with the 2019 Docker Customer Innovation Award today at DockerCon. We launched the awards last year to recognize customers who stand out for how they are using  Docker Enterprise to drive transformation within IT and their business.

These are companies ranging from cruise lines to established “brick and mortar” enterprises, some of whom have been in business for well over 100 years. These are their stories.

Creating Exceptional Experiences: Carnival Corporation

         

Carnival’s first commitment is to creating fun, memorable and safe experiences for its guests. As the largest cruise line in the world, Carnival hosts over 12 million customers annually on 110 ships and at 15 resorts. Technology plays a key role in providing a world-class consistent customer experience.

Carnival leverages Docker Enterprise to build, run and update over 300 services on its new Medallion System, a necklace or wrist band IoT token unique to each passenger used to pay for drinks or as a key to your room. Adding or changes services, or testing new ones, is easy with the Docker Enterprise platform. The system is running on two ships today, with plans to expand this year to six more ships.

Culture Transformation Award: Citizens Bank

 

Home mortgages call to mind endless paperwork, not digital innovation. The Citizens Bank mortgage division established an innovation team to challenge the core assumption that the bank had to move slowly and carefully when it changed or added any services.

Rapid innovation supported by Docker Enterprise now allows the team to “fail fearlessly” and take new ideas from concept to running in a week — without putting the bank at risk. Before Docker, the team only managed a few software deployments a week. Today, they average over 200 deployments daily and run over 2,000 containers.

Digital Transformation: Liberty Mutual

     

What do you do if you have 106 years of accumulated technical debt but need to evolve and offer new digital services to remain competitive? Liberty Mutual started its digital transformation journey in 2016 by changing the way it builds software, using Docker Enterprise as the catalyst.

Through the company’s partnership with Docker, Liberty Mutual has been able to modernize traditional applications, and move these to the cloud in a more automated, portable, and cost-effective way, as well as enable new teams to write modern services quickly building on from open technologies.

“Docker has been a transformational technology. It helped us dissolve our previous assumptions about how app development, operations and security could be done.”

  • Mark Cressey, SVP & GM, Hosting Services
Global Impact: Lindsay Corporation

     

Lindsay started out as an industrial agricultural equipment manufacturer in the 1950s. Even ten years ago, their primary product was steel-based sprinkler systems for farms. Today, Linday is an IoT company that delivers value to customers through sophisticated software and sensors.

Core to Lindsay’s mission — feeding the world’s growing population in the most sustainable way possible. That means using its software to make intelligent decisions about watering crops, increasing yields and saving 700 billion gallons of water in the process. Docker Enterprise helps Lindsay build, test and deliver new capabilities to farmers rapidly.

“Whether it’s feeding 10 billion people by 2050 or helping to conserve the water resources that we have on earth, with our new architecture based on Docker Enterprise, the sky is really the limit.” — Brian Magnusson, VP Technology and Innovation

CIO of the Year: Nationwide

   

In 2014, it took three years to complete a software project at Nationwide — far too long to keep up with the rapid shift to digital. Even a simple software deployment took a week. IT undertook an initiative to turn that on its head.

Fast forward to today and a software deployment at Nationwide takes an hour, a 100x improvement. Critical applications in the Life, Property & Casualty and Claims business units have been containerized with Docker Enterprise. The company estimated it already saves $2 million a year in application costs. The company has a “container first” strategy and plans to migrate all existing apps to containers by 2021.

Operating at Scale: Visa

       

Visa processed $11 trillion in transactions in over 160 currencies last year. How does the world’s largest payment company scale to 65,000+ transactions a second?

By containerizing two critical payment services on Docker Enterprise, Visa achieved a 10x increase in scalability and handled over 100 million transactions on Black Friday. It can scale rapidly from 100 to 800 containers to meet demand, while maintaining efficient infrastructure utilization.

We’re pleased to recognize these six customer with the 2019 Docker Customer Innovation Award.


New blog: #Docker Customer Innovation Awards recognize digital transformation @CarnivalPLC, @CitizensBank, @Work at Liberty, @LindsayIrrigate, @Nationwide, @Visa
Click To Tweet


The post 2019 Customer Innovation awards: 6 Stories of Transformation in the Enterprise appeared first on Docker Blog.

2019 Customer Innovation awards: 6 Stories of Transformation in the Enterprise syndicated from https://koresol.wordpress.com/

Vote Now for April’s Site of the Month and Win a Year’s Free Pro Plan in the Awwwards Directory!

Checking out our Site of the Month nominees is one of the quickest ways you can get inspiration from the best projects on the web right now. Have a look…
Vote Now for April’s Site of the Month and Win a Year’s Free Pro Plan in the Awwwards Directory! syndicated from https://koresol.wordpress.com/

CodeSOD: How Many Quarters to a Dollar?

Myrtis joined Initech as their first on-staff software developer. Up to that point, Initech outsourced all the software development on their payroll/billing system. The contractor kept raising their rates, Initech’s business needs kept growing, and eventually they decided it was time to hire an in-house developer.

Which meant Myrtis got to inherit all of that outsourced development. All that code, all of which had some pretty significant financial implications if it contained any bugs or errors, all developed by a third-party to a third-party.

Imagine, for example, that you need to round to the nearest quarter. That is to say, 1.12 rounds to 1.00, while 1.19 rounds to 1.25.

public static double RoundToQuarter(double input)
{
    int start = Convert.ToInt32(input.ToString().Contains(".") ? input.ToString().Split('.')[0] : input.ToString());
    double dec = input - start;

    if (dec < 0.13)
        dec = 0.000;
    else if (dec < .38)
        dec = 0.250;
    else if (dec < .63)
        dec = 0.500;
    else if (dec < .88)
        dec = 0.750;
    else
    {
        dec = 0.000;
        start += 1;
    }
    return start + dec;
}

The hand-coded break-points for the rounding are almost acceptible, since there are only four of them. You couldn’t rely on one of the built-in rounding methods to handle that specific case.

Speaking of built-in rounding methods, why use that at all? If you want the integer part of a number, you can just ToString it and split on ., assuming your software is never going to run anywhere they use , as the decimal seperator.

The real, WTF, though, is knowing that this is financial data. Even though we’re rounding to a fairly low precision result, all the inputs and all the outputs are double. You just know all the currency values all through this application are doubles.

//thedailywtf.com/images/highlight/highlight.pack.js
hljs.initHighlightingOnLoad();

[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!


CodeSOD: How Many Quarters to a Dollar? syndicated from https://koresol.wordpress.com/

All That Glitters

Iron disulfide pyrite

Sometimes the writing is on the wall; sometimes, you know you have to get out. Today's submitter, Pietyr, was in just that sort of situation. He decided to head for greener pastures, hoping for a job with a good atmosphere, someplace where he could take it easier and enjoy his work more.

Initech was a startup, one that didn't have any clients yet. No external deadline pressure, just venture funding and free beer Fridays. Pietyr gave them a call and spoke with their receptionist-who-was-also-HR, Chrysanthemum.

"May I call you Chrissy?" he asked, trying not to laugh.

"You can call me anything you like, Sugar, so long as it's not 'late for dinner.'"

Pietyr scored an interview same day—"Come on over when you get a chance, darling, we're here all afternoon"—and so, at 4:00, he called off for a doctor's appointment and drove to the site. It was a suite in a larger building, all one dim room, lit mostly by Christmas lights … in March. A dozen people crowded onto long tables, plugging away at MacBooks, entirely uninterested in his arrival. While Chrissy answered phones, he watched a good ten minutes of Kindergarten Cop on the large TV they clearly had on for white noise in the background.

At least it's different, he told himself.

"Mr. Taberd will see you now," Chrissy said, interrupting Arnold.

"Ah, right. And that is …?"

"The CTO."

With no further preparation than that, he was ushered into a side room, little bigger than a closet, into which a lean blond man and a midsize desk had been crammed unceremoniously. He shook hands, sat, and let the CTO do most of the talking.

"What's the biggest issue with cloud computing?" Mr. Taberd finally asked, leaning forward.

"Security?" guessed Pietyr.

"Wrong! It's monitoring. When you don't have access to the servers, you don't know what they're doing! But that's where Initech comes in," boasted the blond, in what was clearly a prepared elevator pitch. "Windows is always doing things under the hood, and it's impossible to tell what at scale. Not without a centralized system. What we're doing here is hooking the Windows API calls—"

"Which ones?"

"All of them! Every API in the user, gdi, and networking DLLs, plus some of the internal kernel functions. We hook them through a backdoor my boys have cooked up, save off all the parameters whenever they're called. Our background process reads those parameters from shared memory, ships them to a cluster of databases—we're doing about 250 elastisearch instances per server—and reads it all into our responsive web frontend. That way you know exactly what it's doing at all times!"

Pietyr could tell right away it would never work. Not even in Windows XP, let alone more secure versions. Too much overhead; it would bring the monitored server to its knees.

But, on the other hand, free beer. And hey, if the product never sold, he could kick back and take it easy, right? As soon as Tabard mentioned free lunch every day—"Thanks to our Venture Capital funds!"—he was in.

He took the job, working on the low-level hook code so that all the cloud nonsense was someone else's problem. A month later, he received a letter informing him his shares were effectively worthless. Fine by him, since he had no shares anyway.

It took another month before he casually asked a coworker how long they'd been working there.

"Oh, not long. Only about two years."

"Really? You must have been here since the beginning then, or nearly," Pietyr commented. He would have guessed from the codebase the company had only been running six months or so, but he kept that to himself.

"No, no. Jan has been here all seven years, I've only been here two."

Pietyr stared. "Seven years?! You've been working on this with no customers for seven years?!"

"Well, I heard a rumor we've got a client about to sign up for the beta."

"A rumor." Pietyr sighed, firmly placing the conversation in the not-my-business bucket, and got on with his work. Still, the sense of unease didn't leave him.

A month after that, the unthinkable happened: Taberd not only left his little office, but turned off the television. "Alright, everyone, listen up! Stop what you're doing. We're out of money."

And just like that, Pietyr was back on the job market. That day, he learned a valuable lesson: don't let free beer convince you to ignore red flags.

[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!


All That Glitters syndicated from https://koresol.wordpress.com/

Error’d: Error Inception

"Behold how TDWTF commenters get their start in life!" Adam G. writes.

 

"We have this cable company called UPC here in Slovakia, and my freshly installed router failed showing Schrodinger's Connection symptoms," writes Daniel.

 

Mark J. wrote, "Apparently, AliExpress chooses its customers very carefully.

 

"I don't think that Medium knows what humor really is…or does it?" Bellons writes.

 

Tobias H. wrote, "While reading an article on heise.de, something apparently happened…or not?"

 

"While trying to purchase Satisfactory I got this message that aims to warn those who are not yet born," writes Nigel.

 

[Advertisement]
Forget logs. Next time you're struggling to replicate error, crash and performance issues in your apps – Think Raygun! Installs in minutes. Learn more.


Error’d: Error Inception syndicated from https://koresol.wordpress.com/