Best practice for method with large number of parameters

I'm writing a utility that will likely be called by a script that uses argparse, but should be useable by any script. The engine object constructor needs a dozen or so parameters to tune its behavior. The question is: What is the best way to allow the caller to send the necessary parameters without requiring extra work setting params that have defaults.

First thought: Since some users will have an argparse.Namespace instance already, I might make use of that. But other users would need to create a Namespace (or just a subclass of object) which seems like a problem.

Second thought: Normal methods are written to just take a sequnce of (named) parameters, which is what programmers will expect. Better yet, Python allows **kwargs in constructor's parameters, and vars(aNamespace) is a map, so it seems we could call EngineObject(*args, **vars(an_argparse_namespace)) and have the best of all worlds. But, alas, if the caller's Namespace instance has attributes that the Engine constructor doesn't recognize, it won't run.

Third thought: But... if we write the constructor as __init__(self,arg1,arg2,arg3=def3,...argN=defN, **kwargs) that final **kwargs will eat all the extra attributes. I like this... But, as I found by accident, if I pass a needed ..., misspelled=value, ... there is no warning that I got it wrong because that **kwargs eats the misspelled parameter name just like it would eat other named parameters that we don't care about.

Current thought: I now have this code:

class Engine:
    @classmethod
    def clean_map(cls, amap):
      """return a map holding only valid keys/values from amap"""
       ...
       return safe_map

  def __init__(self, arg1, arg2,
               arg3=default3,
               ...
               argN=defaultN)
      self.arg1 = arg1 # etc
    ...

This gives me a slightly awkward way to give every user a good experience: Users who are just calling the service can pass the parameters they care about... and they'll be warned if they misspell something. Users who have an argparse.Namespace object can write this somewhat clunky code: engine = Engine(**Engine.clean _map(vars(myNamespace)))

An alternative would be to wrap the clean_map method into an alternate constructor:

class Engine:
    @classmethod
    safe_construct(cls, amap):
        ...
        return cls(**safe_map)

So: What would be the ideal way to handle this? Is my "current thought" the best way to be Pythonic? Do you prefer the "safe_construct" technique to what I'm now using? Something else?

University of Wisconsin Offers Free Course on Creating WordPress Websites

The University of Wisconsin is offering a free self-paced course on Creating WordPress Websites for students through its Stevens Point branch. It is one of ten free courses offered to the general public in a catalog that includes courses on management, communication, personal finance, customer service, and small business marketing. Creating WordPress websites has become an essential skill, as the software now powers 37.5% of all websites ranked in the top 10 million by Alexa.

The WordPress course is designed to give users hands-on experience in building a website. Students will learn how to design pages, add content, and customize their sites using themes and plugins. Self-hosted sites require paid hosting, and SiteGround has donated a free 90-day hosting account and temporary domain for students to use while taking the course. Instructions for how to sign up are included in Lesson 1.

The course is 24 hours and covers a wide range site creation topics, including creating content, uploading images and files, the basics of optimizing for usability and search engines, and how to analyze stats and promote content to social media. This is a good way to get started for anyone wanting to learn WordPress with a more structured approach. It may be helpful for new users who are exploring a career change or wanting to create a website for a new business.

Creating WordPress Websites is a non-credit course and is suitable for students who are comfortable learning without an instructor. The registration deadline for the free courses is June 30, 2020. Students will have three months of access to the course after registration.

Variadic Template C++: Implementing Unsophisticated Tuple

From C++11, std::tuple is an incredible expansion to Modern C++ that offers a fixed-size col­lec­tion of het­ero­ge­neous values. Un­for­tu­nately, tu­ples can be somewhat dubious to manage in a conventional fash­ion. But, subsequently released C++ stan­dard in­tro­duced a few fea­tures and helpers that greatly re­duce the nec­es­sary boil­er­plate. 

So, in this article, I will explain the variadic template in C++ with the help of unsophisticated tuple implementation. I'll also walk you through a tricky part of tuple i.e. loop through tuple element. Because I have covered the variadic template in my prior article i.e. C++ Template: A Quick UpToDate Look, my focus here would be a blend of variadic template and tuple implementation with more up to date C++ gauges.

Proposal to Rename the ‘Master’ Branch of WordPress-Owned Git Repositories

Yesterday, core contributor Aaron Jorbin proposed renaming the default “master” branch for all WordPress-owned Git repositories to “main.” The proposal comes among a flurry of related terminology changes that the larger tech community is considering around oppressive language.

Based on the ongoing discussion in the comments of the proposal, the term “trunk” has gained popularity, and the original post has been updated in favor of that term. If it moves forward, trunk would be more in line with core WordPress, which uses Subversion (SVN). It would also make sense along with the “branch” terminology already in use with both SVN and Git — tree, trunk, and branches.

“As a part of tearing down the systems of oppression that exist in the world, WordPress should remove references to master and replace them with trunk in all git repositories,” wrote Jorbin.

Amidst the backdrop of the Black Lives Matter movement and following the death of George Floyd, the tech community has been taking a deeper look into its systems and determining what changes it can make. While there are larger systemic issues at play, many are determined to remove any potentially oppressive or discriminatory terminology. The idea is not that these minor changes will create an evolution overnight but that they are small pieces of the much bigger picture — cogs in the machine that must move for the wheel to turn.

“This is a small move, but if it makes one more person comfortable contributing to a WordPress project, it will be worth it,” wrote Jorbin.

GitHub should soon be making a similar change across its platform. In response to a tweet calling for GitHub to lead the charge and rename the default “master” branch to “main,” CEO Nat Friedman said they were already working on a solution. It is unclear how this will work going forward and whether it would affect existing repositories. For now, it seems GitHub is on board.

Thus far, the WordPress proposal has been mostly met with support. However, there was some dissent.

Core contributor Zebulan Stanphill argued that language is oppressive based on context and, in this context, the change does not make sense. “Similarly, no one in their right mind is going to think you support human slavery when you use the term ‘master branch,'” he wrote in the comments of the proposal. “The term ‘master’ itself is already used far outside of the context of slavery. Think novice->pro->master. Think also: mastering the craft, remastering music, and etc.”

As harmless as the word “main” seems in most Western cultures, a comment posted by Mike Schroder (original Japanese text by Takayuki Miyoshi and translation by Shinichi Nishikawa) pointed out that it was problematic in Japanese culture. “In Japan, for example, to put ‘main’ and ‘others’ as different groups has been utilized as an excuse to justify discrimination,” said Miyoshi. “Not caring about suppressing the Ainu people and their culture at all is possible because of the assumption that Yamato folk is the main and others are secondary. I now came to a point to think we should consider that to set one thing as ‘main’ creates marginals that get oppressed.”

Language is not always easy, especially when addressing a global community, each with their own terms that are possibly discriminatory. For now, trunk seems to be a good fit while throwing a nod to WordPress’s SVN roots.

This would not be the first time that WordPress has made a move to change terminology such as this. David Artiss, a support engineer at Automattic, created a ticket seven months ago to rename “comment blacklist” to “comment blocklist.” The change, which replaced only the user-facing text, went largely unnoticed and landed in WordPress 5.4.

Jason Coleman, CEO of Stranger Studios, also opened a more extensive ticket two days ago. It calls for changes of any use of “blacklist” to “blocklist” and “whitelist” to “safelist,” even within the code and database options. Such changes would be backward compatible and not break sites upon upgrade.

Change is almost certainly coming. The big decision is going to be around what the new terms will be.

For developers who want to rename the default branches of their own Git repositories, there is an existing project with instructions and a GitHub action for doing so.

A Monthly Update On All Things Smashing

A Monthly Update On All Things Smashing

A Monthly Update On All Things Smashing

Iris Lješnjanin

The entire Smashing team has been doing its very best to bring you live sessions with real experts — people with practical experience who love to share what they have learned throughout their careers. We organized Smashing Meets on three days — events that were open to everyone in the web community. With sessions on performance, CSS, GraphQL, and creative courage, we made sure to leave plenty of time for Q&A, networking, competitions and prizes.

We’re overwhelmed with the feedback we’ve received since then; many of you seemed to mostly enjoy spending time with speakers, and asking questions directly. A huge thank you again to everyone who joined in — it was such an incredible experience to have shared with you all!

A still image of the Smashing Meets event that took place on June 9 2020 including Henri Helvetica, Yiying Lu and Vitaly Friedman
Henri Helvetica, Yiying Lu and Vitaly Friedman live on screen at the recent Smashing Meets event. (Image credit: Yiying Lu)

Smashing Meets Schedule Overview (May & June)

May 18 Yiying Lu Creativity in Cross-Cultural Communication Talk slides Watch video →
May 18 Phil Hawksworth Building With JAMStack: Keeping UIs And APIs Aligned Talk slides Watch video →
May 18 Mark Boulton Accessible Typography Talk slides Watch video →
May 19 Mandy Michael Fun With Browser and Sensor APIs Talk slides Watch video →
May 19 Rachel Andrew Hello, Subgrid! Talk slides Watch video →
May 19 Mark Boulton Accessible Typography Talk slides Watch video →
June 9 Henri Helvetica Moving Pictures: A Snap Shot of The Future Of Media Talk Slides Watch video →
June 9 Rachel Andrew The Evolution of Responsive Design Talk Slides Watch video →
June 9 Christian Nwamba GraphQL APIs for Frontend Developers Talk Slides Watch video →
June 9 Yiying Lu Creative Courage Talk Slides Watch video →

Smashing Online Workshops: Coming Up Next

Mark your calendars! We’ll be organizing even more online events in the next weeks. Whether the spotlight shines on CSS, accessibility, performance or UX, we want to help you boost your skills and learn practical, actionable insights from experts in the industry.

The previous workshops have been incredibly popular with many becoming sold out, so do check the details and save your spot as soon as you can.

Date Name Topic
July 2–17 Vitaly Friedman Buy! The eCommerce UX Workshop See details →
July 7–21 Brad Frost Design Systems See details →
August 17–31 Susan and Guthrie Weinschenk Behavioral Design See details →
August 20–Sept 4 Yiying Lu Designing for a Global Audience See details →
Sept 17–Oct 2 Natalia Tepluhina Vue.js: The Practical Guide See details →
Staying up to date can be so difficult. It’s a jungle out there, but we have you covered!
See online events →

One last thing. In case you find yourself thinking twice about joining in a Smashing workshops just because you think your manager could need just a little bit more persuasion, then we’ve got your back with a neat lil’ template: Convince Your Boss. Good luck!

Our Latest Addition To The Smashing Books: Shipping Now

We’re so proud to have officially released Paul Boag’s book, “Click! How To Encourage Clicks Without Shady Tricks”. It is a detailed guide on how to increase conversion and boost business KPIs without alienating customers along the way, and we’re sure you’ll find it tremendously useful.

A photograph of the hard copy of the latest Click! book written by Paul Boag
Quality hardcover. Free worldwide shipping. 100 days money-back-guarantee. Tell me more →

Smashing Podcast: Tune In!

Smashing Podcast18 episodes in, the Smashing Podcast has been better than we had ever expected! Every two weeks, Drew McLellan speaks to folks from different backgrounds, and there’s always so much to learn and share! You’re always welcome to tune in and share your questions and thoughts with us anytime.

We publish a new article every day on various topics that are current in the web industry. Here are some that our readers seemed to enjoy the most and have recommended further:

Best Picks From Our Newsletter

We’ll be honest: Every second week, we struggle with keeping the Smashing Newsletter issues at a moderate length — there are just so many talented folks out there working on brilliant projects! Kudos to everyone involved!

Interested in sponsoring? Feel free to check out our partnership options and get in touch with the team anytime — they’ll be sure to get back to you right away.

P.S. A huge thank you to Cosima Mielke for writing and preparing these posts!

Modern CSS Solutions For Old CSS Problems

We all know that CSS can sometimes be tricky to master. Just think of the classic question of how to center a div. In “Modern CSS Solutions for Old CSS Problems”, Stephanie Eckles explores solutions to those big and small CSS problems she has been solving in the last 13 years of being a front-end developer.

Modern CSS Solutions

Apart from the old centering issue, the series explores challenges like creating elements of equal height, making dropdown menus accessible, styling buttons, and much more. Be sure to check back regularly as Stephanie keeps adding new topics. Brilliant!

Illustrations For Everyone

Illustrations are a great way to add a personal touch to a design. However, not everyone is a born illustrator and not every project has the budget to hire someone who masters the craft. During the lockdown, Pablo Stanley and a few of his friends decided to change that and created a tool that makes art more accessible and gives everyone the ability to use illustrations in their creations. Meet Blush.

Blush

Blush is a collection of 13 mix-and-match illustration libraries created by artists from around the world. Whether it’s characters, cityscapes, plants, food, or a piece of abstract art, you can pick your favorite illustration from one of the packs and customize every little detail until you have the combination you need to tell your story. As Pablo puts it, it’s “like playing legos made of vectors”. The illustrations can be downloaded for free as high-quality PNGs. If you are an illustrator yourself and would like to make your work available to other makers, too, you can apply to get featured in Blush. A fantastic example of sharing and caring.

Learn Flexbox With Code Tidbits

You’ve always wanted to learn Flexbox but the whole undertaking seemed a bit, well, daunting? It doesn’t have to be. In fact, it might only take 30 code tidbits to get you on the path to mastering some Flexbox magic. Samantha Ming has got your back.

Flexbox30

In her free course Flexbox30, Samantha takes you through 30 short and crisp Flexbox lessons. After learning the core concepts of Flexbox, you will explore the ins and outs of parent and child properties. Each lesson comes with a cheat sheet that you can download which makes the course also a great refresher if you already know your way around Flexbox but struggle with some of the properties.

Global Website Speed Profiler

Performance benchmarking tools usually measure performance form a single location. But how does your site perform for real-world users who aren’t based in that one location? To get more precise results for their own market, the folks behind the WordPress security plugin Wordfence built Fast or Slow, a tool that measures real-world performance from different locations around the world.

Fast or Slow

Fast or Slow gets its data from a network of 13 servers in 13 cities around the world. Each server was calibrated to have the same performance so that the speed measurements give a true indication of what the site feels like to a real user. The performance test provides you with an overall score of a site’s performance and breaks the results further down by geographic location, while audits on CSS minification, image optimization, caching, and more help reveal specific performance bottlenecks. Fast Or Slow is free to use.

Sleek Browser Frames For Your Screenshots

With screenshots, there are usually two options: You take a screenshot of the entire browser window with browser extensions and maybe even bookmarks visible or, if you want something less distracting, you decide to only take a screenshot of the site without any border at all. If you’re looking for a more sophisticated solution, Browserframe might be for you.

BrowserFrame

Just drag and drop your screenshot into the tool, and it wraps it into a neat browser frame. There are multiple browsers, operating systems, and themes to choose from, and you can adjust the background color, shadow, padding, and some other details before you download the image. Perfect for blog posts, social media, slides, or wherever else you might want to use a screenshot.

SVG Path Data Syntax Explored

Do you know what the SVG path data syntax actually means? If not, you’re not alone. Mathieu Dutour has been working with SVGs for quite some time but always struggled to understand the path data structure. That’s why he built a visualizer for it.

SVG Path Visualizer

The SVG Path Visualizer visualizes the SVG path data you enter and lets you discover all its different commands. There are also several examples you can explore to get more familiar with the syntax. An insightful look into the skeleton of an SVG.

The Future Is Here

Imagine you are working on a project and want to add a picture of a book to it. You have the book right beside you on your desk, so you take out your phone, take a picture of the book, send the picture to your computer, open it in Photoshop, remove the background, and, finally, include the picture in your file. Well, now what if you could copy and paste the book from reality onto your screen, just where you want it to be? What might sound like science fiction, is already possible today.

AR Copy Paste

The research prototype AR Copy Paste allows you to copy elements from your surroundings and paste them into an image editing software. Three independent modules make it happen: a mobile app, a local server that acts as the interface between the app and Photoshop and finds the correct position on your screen, and, last but not least, an objection detection/background removal service to cut the image into shape. An impressive peek at the future of AR.

Black Illustrations

Black people and people of color are often underrepresented in illustrations and visuals. To spark change in the digital landscape, the team at 5four created Black Illustrations, illustration packs that paint a more diverse picture and show black people and people of color in a myriad of tasks.

Black Illustrations

There are six illustration packs that can be used on websites, pitch decks, infographics, or anywhere you like. Two of the decks are free to download: “The Office Hustle” shows people in an office environment, working from home, and having conversations, as well as in a healthcare setting, while “The Movement Pack” calls attention to #BlackLivesMatter and the fight against racial inequality. Other packs include education- and lifestyle-themed images. Beautiful designs with a powerful message.

See Easing Curves In Action

Movement in the real world is something fluid, no harsh or instant starts or stops, no constant speed. Easing curves help us bring that natural feel to motion on the web. However, in practice, they can be quite abstract to grasp, too.

Easings

With Easings, Paul Macgregor built a useful tool to visualize the effect common easing curves have on a range of interfaces — from a gallery carousel to a side menu, scroll jack, and modal. Just choose an easing curve from the collection to see it in action or enter a custom one. One for the bookmarks.

Insights Into How Developers Work Today

Since almost a decade, the yearly Developer Survey conducted by Stack Overflow is the largest survey of people who code. This year, they made it more representative of the diversity of programmers, asking 65,000 developers from around the world how they learn, which tools they use, and what they want. The survey was conducted in February and the results offer a comprehensive look inside the community.

2020 Developer Survey

The survey covers the developers’ professional and demographical background, looks at tools and their popularity, what the respondents’ dev environments look like and how they learn and solve problems, just like at their career values, job priorities, and working conditions. Interesting insights guaranteed.

CSS Art In A Single Div

What can you do in a single div? Lynn Fisher has a lot of creative answers to this question, as her CSS drawing project A Single Div shows.

A Single Div

Every drawing is made up of CSS living inside a single div element and uses a combination of Pug for templating and Stylus for CSS preprocessing. From lettering and geometrical patterns to random objects and little characters, each colorful tile is a wonderful example of what can be accomplished with CSS.

A Magic Notebook For Exploring Data

Open source has transformed software development, making sharing, collaboration, and transparency the norm. Inspired by this, Observable aims at reimagining data science for a connected world. To make it more approachable, accessible, and social.

Observable

Described as a “magic notebook for exploring data and thinking with code”, Observable lets you sketch with live data. You can prototype visualizations, connect to Web APIs, and see your “notebook” update instantly when changes are made. Learning from one another, sharing and reusing components with a community of fellow authors is a key part of the concept, teams are even able to edit a notebook together in realtime. Now what to make with it? Reports, explanatory visualizations, UI prototypes, documentation, art projects, visual designs — only your imagination is the limit.

Smashing Editorial (cm, vf, ra)

Debug a Node.js Application Running in a Docker Container

This blog post shows how you can debug a simple Node.js application running in a Docker container. The tutorial is laid out in a fashion that allows you to use it as a reference while you’re building your own Node.js application and is intended for readers who have prior exposure to JavaScript programming and Docker.

Prerequisites

  1. Docker. For details about installing Docker, refer to the Install Docker page.
  1. Node.js 10 or higher. To check out if Node.js is installed on your computer, fire up a terminal window and type the following command:
Shell
 




x


 
1
node -v


If Node.js is already installed, you'll see something like the following: 

#273: Assets Keep Getting Better

Show Description

Asset Hosting just keeps getting better! Marie and Stephen talk about even more new features added to PRO asset hosting including new CORS-proof asset URLs, image optimization, scaling or saving as a new image, and how CodePen decides to build features like this out.

Time Jumps

  • 01:49 What’s new in Asset Hosting?
  • 07:23 Optimizing images inside assets
  • 14:58 Sponsor: Netlify
  • 17:39 Saving or Scaling Images
  • 24:13 Building for ourselves as well as customers

Sponsor: Netlify

Netlify is the fastest way to build the fastest sites, Jamstack style. Netlify is a web host that hosts your static files, but for not-so-static sites. The static file hosting is just so that the site can be served over a global CDN as quickly and securely as is possible to do. Any kind of functionality is possible through things like built-in form processing, auth, and cloud functions, and the developer experience is second to none.

Show Links

CodePen Links

The post #273: Assets Keep Getting Better appeared first on CodePen Blog.

Profile Software Launches Acument-net eFX

Profile Software, a banking and investment management solution provider, has launched Acumen-net eFX. The new solution allows banks and their clients to access and manage risk associated with foreign exchange. The new offering builds on the company's existing treasury management platform.

Business Agility: What Every Leader Needs to Know

There is a lot of hype, confusion, and conflicting messages around Business Agility. Organizations know that they need to evolve to compete in the dynamic marketplace yet are struggling to make real progress. In this article, we will cut through the noise to give you the understanding and practices needed to unlock Business Agility in your organization.

Practical Definition of Business Agility

What is Business Agility? Take a moment to reflect on your understanding:

9 Free Best Code Editors for Windows and Mac In 2020

It is always exciting for developers from all over the world whenever they get to showcase their best code editor at computer expos and tech conferences. On that note when we talk about free code editors for Windows and Mac to use in the year 2020, we cannot help but wait in anticipation for brand-new features to use right away.

In this write-up, we will talk about the best coding software for multiple platforms. However, we will lay extra emphasis on Windows OS and Mac OS because they are popular operating systems out there right now.

MEAN Full Stack on Amazon AWS

This is the first and main blog, in this, I will explain the overall idea. Please be informed that this is going to be a blog series exploring all the aspects of running the full stack application on AWS (Amazon Web Services). 

The main goal is to share the learning related to AWS but I will also explain a bit about Full stack application which we will implement in MEAN stack (Mongo, Express, Angular and Node).

Should You Hire A Developer Or Use The API For Your Website’s CMS?

It doesn’t matter how powerful or well-rounded your chosen CMS happens to be: there can still come a point at which you decide that its natural state isn’t enough and something more is needed. It could be a new function, a fresh perspective, or improved performance, and you’re unwilling to settle for less. What should you do?

Datasources, what, why, how?

Hope this post clarifies how a datasource works within a Java EE server and the reasons why you would need a XA Datasource when you have distributed transactions.

The origin of this post is to provide a basic understanding so that the user feels confident when to use or not to use Datasources and XA Datasources.