Wednesday, November 1, 2017

Calling For Wisdom

Lovely clear typography in this One Pager explaining design methodology Calling For Wisdom. Really feeling this Anton and Lora font pairing.

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Ann Handley’s Best Practices for Creating Top Notch Content - #infographic

The content of your website is your no.1 sales tool. Photos, embedded tweets and other entertaining elements can be crucial in creating an attractive, visible and efficient site, but the content is what sells. Appealing and user-friendly content permits your readers to discover more about your...

[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Web Desk via Digital Information World

Data Visualization With DataTables.js and Highcharts.js

Kotlin From Scratch: Exception Handling

Kotlin is a modern programming language that compiles to Java bytecode. It's free and open source, and makes coding for Android even more fun.  

In the previous article, you learned more about object-oriented programming by digging into abstract classes, interfaces, inheritance, and type aliases in Kotlin. 

In this post, you'll continue to learn about programming in Kotlin by learning about exceptions and how to handle them. 

1. Exception Handling

Exceptions are used to indicate a problem in our code during a program's execution. Exception handling is the capability to address (or handle) the exception that might occur. If we don't handle any exception that occurs, our program will stop execution abruptly—crashing our app immediately. 

Exception handling allows our program to continue execution even if there was an exception (though it is highly recommended to log your exceptions and report them using a crash reporting tool like Crashlytics).   

In Java, we have two kinds of exceptions: checked and unchecked. I'll briefly explain both of them, but we'll start with unchecked exceptions. 

Unchecked Exceptions

These are exceptions that are thrown because of flaws in your code. They are a direct or indirect subclass of the RuntimeException superclass. 

Examples of unchecked exceptions include:

  • ArithmeticException: thrown when you divide by zero.
  • ArrayIndexOutOfBoundExceptions: thrown when an array has been accessed with an illegal index. 
  • SecurityException: thrown by the security manager to indicate a security violation.
  • NullPointerException: thrown when invoking a method or property on a null object.

A method that might throw an unchecked exception doesn't contain any information about the exception thrown on its method declaration. 

These types of exception can be prevented by coding right. In the code above, we should have checked if the denominator was zero before performing the operation. For these exceptions, the developer doesn't need to catch the exception using the try...catch block. In other words, we aren't forced by the compiler to wrap the code that might trigger the exception in a try...catch block. Instead, we should just make sure the exceptions never occur in the first place.

Also, remember, Kotlin is a null safe language. In other words, it can help us avoid getting NullPointerExceptions in our code. You can read the Nullability, Loops, and Conditions post to get a refresher on null safety in Kotlin. 

Checked Exceptions in Java

A method that might throw a checked exception needs to declare so in its method signature using the throws keyword. If you call a method that throws a checked exception, you either need to throw it again from your function or to catch it and handle it using a try...catch block. 

Checked exceptions are exceptions that are checked at compile time. These kinds of exceptions inherit from the Exception class. An example of this kind of exception is IOException. This can occur when you try to access a file that can't be opened because it doesn't exist. (FileNotFoundException is a subclass of IOException.)

In the preceding code, we used a try...catch block to handle the IOException inside the editFile() method. We can now call the editFile() method as normal, and the compiler won't complain. 

Looking at the code below, we've refactored the method to instead use the throws keyword in the method signature. This indicates to callers that they need to handle the exception IOException that might be thrown when calling the method editFile().

To call the method above, we need to surround it in a try...catch block to handle the exception.

This has been a brief look at exceptions in Java. Let's now see how Kotlin handles exceptions. 

2. Exceptions in Kotlin

The main difference between Kotlin and Java exception mechanisms is that all exceptions are unchecked in Kotlin. In other words, they are not explicitly declared in the function signatures, as they are in Java.

Here, we have converted the editFile() method to a Kotlin function. You can see that the function doesn't have the throws IOException statement in its function signature. throws isn't even a keyword in Kotlin. 

Also, we can call this function without surrounding it with the try...catch block—and the compiler won't complain. In other words, there's no such thing as checked exceptions in Kotlin. All exceptions are unchecked. (Note that if there is an exception thrown, program execution will stop as normal.) 

If we think this exception might arise, we should still handle it by surrounding the method with a try...catch block—but this is not enforced by the Kotlin compiler. 

If the exception thrown inside the editFile() function is an instance of the IOException class, our catch block will be executed, and we simply print the stack trace for debugging purposes.

The try...catch Block

The try construct with catch and finally clauses in Kotlin is similar to that of Java. 

Here, we are throwing an Exception object inside the try block. Notice we didn't include the new keyword as we do in Java to create a new instance. Also notice that we didn't specify the exception that will be thrown in the function signature as we would have to in Java. 

We handle all subclasses and classes of type Exception in the catch block. The optional finally block is always executed—this is where we typically close any resources or connections that were previously opened so as to prevent resource leaks. For example, if you open a file or create a database or network connection in a try block, you should close or free it in a finally block. 

Note that in Kotlin the throw construct is an expression and can combine with other expressions.

Also, the try construct can be used as an expression.

Here, we assigned the value returned from the try...catch block to the result variable. If the number is not 1, it throws an IllegalArgumentException and the catch block is executed. The false expression in the catch block value will be assigned to the result variable. If the number is 1 instead, then the true expression value will be assigned to the result variable.

Java Interop

Exceptions in Kotlin behave as normal in Java—but I want to make you aware of a useful annotation called @Throws in Kotlin that might come in handy. Because all exceptions in Kotlin are unchecked, developers who consume your Kotlin code from Java might not be aware that your functions throw exceptions. However, you can still add the possible exceptions that might be thrown to a method signature with the @Throw annotation. This will alert Java callers that they need to handle the exception. 

Let's see a practical example of this annotation.

Here, we defined a Kotlin function that can throw an exception IllegalArgumentException only if the type passed to the function is not of type Int

We call this top-level function addNumberToTwo() directly from Java in the following way:

This works fine; the compiler isn't complaining. However, if we want to communicate with Java callers that the addNumberToTwo() top-level function throws an exception, we simply add the @Throws annotation to the function signature. 

This @Throws annotation can accept a comma-separated list of arguments of exception classes. In the code above, we just included one exception class—IllegalArgumentException

Now we have to update our Java code to handle the exception.

If we decompile the Kotlin addNumberToTwo() function, using the Show Kotlin Bytecode feature (if you're in IntelliJ IDEA or Android Studio, use Tools > Kotlin Show Kotlin Bytecode), we'll see the following Java code:

In the generated Java code above (some elements of the generated code were removed for brevity's sake), you can see that the compiler added the throws keyword to the method signature—because we included the @Throws annotation. 

Conclusion

In this tutorial, you learned more about programming in Kotlin by looking into exceptions. We saw that Kotlin doesn't have checked exceptions but that instead, all exceptions are unchecked. We also looked at how to handle exceptions using the try...catch block and saw the usefulness of the @Throws annotation in Kotlin for Java callers. 

To learn more about the Kotlin language, I recommend visiting the Kotlin documentation. Or check out some of our other Android app development posts here on Envato Tuts!

  • Android SDK
    Java vs. Kotlin: Should You Be Using Kotlin for Android Development?
    Jessica Thornsby
  • Android SDK
    Introduction to Android Architecture Components
    Tin Megali
  • Android SDK
    Get Started With RxJava 2 for Android
    Jessica Thornsby
  • Android SDK
    Concurrency in RxJava 2
    Chike Mgbemena


by Chike Mgbemena via Envato Tuts+ Code

#314: The Future of Loading on the Web

Frontend Focus
Issue 314 — November 1, 2017
While native Web Component support isn’t 100% yet, polyfills are available, and this tutorial walks through what’s involved to create your own HTML tags as components.
Ayush Gupta

The idea is to allow Web servers to send back certain headers (e.g. preload link headers) early before the main response.
IETF

A step-by-step tutorial on how to display and annotate PDF files inside your web app using the PSPDFKit JavaScript library. Features include cross-browser support (IE 11 and up), mobile optimized UI, and no server-side component.
PSPDFKit   Sponsor

An interesting creative attempt to create a basic ‘web app’ using nothing but HTML & CSS.
Matt Zeunert

Richard Rutter goes deep on how to improve the readability of your data tables.
Richard Rutter

The takeaway: Google wants you to build PWAs, reduce JS file size, use Web Components, and configure your forms to support autofill.
Dan Fabulich

How popular car selling platform Auto Trader created a high-performance search experience that regularly returns results in less than a second.
Elliot Sumner

Sam Saccone explores recently shipped performance primitives, cutting edge performance techniques, and a glimpse into what the future of loading on the web may hold.
Google Chrome Developers

A helpful overview with some simple things you can do to take positive steps towards a more accessible web. From 2015, but worth revisiting.
Ire Aderinokun

Jobs

In Brief

Microsoft's Plan to Bring Progressive Web Apps (PWAs) to Windows 10 news
Paul Thurrott

W3C Invites Implementations of Preload news
This spec defines the preload keyword that may be used with link elements.
W3C

JS Kongress Munich - The Future of JavaScript on Nov 13-14 news
Join us for two days on the Future of JavaScript (inc. WebAssembly Tooling). Topics include Frontend Architecture, webpack, Angular, React, Perf, etc.
JS Kongress Munich  Sponsor

Unlocking the Benefits of CSS Variables tutorial
The benefits of CSS variables and helpful tips and tricks for working with them.
Jonathan Harrell

How to Build an Interactive Virtual Globe with Three.js tutorial
Jeanne Castillo

3 Commands to Add SSL to 'localhost' for https://localhost on MacOS tutorial
Paul Browne

A Look at the Relatively Uncommon 'output' HTML Element tutorial
Robin Rendle

Using Redux When Building Chrome Extensions tutorial
Bruno Antunes

Emulating CSS Timing Functions with JavaScript tutorial
Ana Tudor

Getting Around a Revoked Certificate in macOS tutorial
Geoff Graham

Using ReactJS, ES6 & JSX to Build a UI (the rise of MERN) tutorial
Part 5 of our Modern Application Stack series - Why ReactJS is driving the development of modern apps.
MONGODB  Sponsor

The Web Began Dying in 2014, Here's How opinion
“GOOG and FB now have direct influence over 70%+ of internet traffic.”
André Staltz

An Animated Flexbox Playground tools
A helpful visual reminder of what effect certain Flexbox properties have.
Blake Bowen

grid-kiss: A PostCSS Plugin to Keep CSS Grids 'Stupidly Simple' tools
Sylvain Pollet-Villard

Koa11y: An Open Source Web Accessibility Tool tools
A desktop app for automatically detecting Web accessibility issues.
Jared Wilcurt

A Better Focus? demo
An attempt at a more ‘visually-pleasing focus for keyboard users’.
CodePen


by via Frontend Focus

#182: 9 Principles of Mobile Web Design

Mobile Dev Weekly November 1, 2017   #182
Peter Cooper recommends
9 Principles of Mobile Web Design — Revisiting a golden oldie that tells us to keep menus simple, keep forms short, have obvious calls to action, plus more mobile Web common sense.
Kim Speier
Brian Rinaldi recommends
The Meaning of AMP — Some thoughts on Google’s ‘alternative facts’ over what the AMP (Accelerated Mobile Pages) project really is.
Jeremy Keith
Sponsored
2017 Video Developer Report - Free Download — 78% of video developers encode for HLS (56% for DASH) - The majority of developers plan to use HEVC in 2018 - Cloud encoding 45% more popular in US than Europe. Get the full 24 page report.
Bitmovin

Brian Rinaldi recommends
I Watched All The Chrome Dev Summit Videos So You Don’t Have To — The takeaway: Google wants you to build PWAs, reduce JS file size, use Web Components, and configure your forms to support autofill.
Dan Fabulich
Brian Rinaldi recommends
Microsoft's Bold Plan to Bring PWAs to Windows 10 “I recently spoke with Microsoft’s Jeff Burtoft and Aaron Gustafson about the company’s plans to bring Progressive Web Apps to Windows 10.”
Paul Thurrott
Holly Schinsky recommends
deviceframe: Put Device Frames Around Your Mobile/Web/Progressive App Screenshots
Brian Hann
Mobile Web
Brian Rinaldi recommends
A New Day for PWAs “With Service Worker coming in Safari, the single biggest obstacle to fully adopting Progressive Web Apps is being removed.”
Jeff Cross
Holly Schinsky recommends
Workbox: An Easier Way of Adding A Service Worker to Your Web App — How to use the ‘Workbox’ JavaScript toolbox to easily add service workers to your progressive web apps.
Bakani Pilime
Chris Brandrick recommends
Samsung Internet V6.2 Now Stable — Includes an updated Chromium engine, support for CSS Grid and experimental features (behind flags).
Jo Franchetti
Chris Brandrick recommends
React Native: 4 Steps to Improve Your Workflow As A Mobile Developer — Some tips to boost your productivity when creating mobile apps in React Native.
Eliasz Sawicki
Brian Rinaldi recommends
React Virgin: The React-Native UI Kit You've Been Looking for
Trixie
Holly Schinsky recommends
Combining Graphical And Voice Interfaces For A Better User Experience — An introduction to​ ​multi-modal​ ​interfaces as​ “​a​ ​more​ ​human​ ​way​ ​of​ ​communication​ ​between​ ​user​ ​and​ machine”.
David Pasztor
Holly Schinsky recommends
Consuming Remote Data via HTTP in a Vue App
Nic Raboy
Hybrid Apps
Za'e Johnson recommends
Creating Layouts within Ionic using CSS Grid
Mastering Ionic
Chris Brandrick recommends
Ionic: 2017-18 Roadmap — What the next 6 to 12 months looks like for everything Ionic.
Max Lynch
Chris Brandrick recommends
How to Use Font Awesome in an Ionic Application
Aman Mittal
Native Development
Brian Rinaldi recommends
Android Studio 3.0 Release — A major release of the official IDE for Android development, including a variety of new features and improvements.
Google
Brian Rinaldi recommends
The Android Oreo 8.1 Developer Preview Is Now Available — Google has released the latest developer preview of Android Oreo. 8.1 will be released in December, but Android Beta Program users can test it now.
The Verge
Sponsored
Best Practices for Architecting Highly Monitorable Applications — Is your application easy to monitor in production? Many applications are, but sadly, some are designed with observability as an afterthought.
VividCortex

Holly Schinsky recommends
Why Your Push Notifications Never See The Light of Day — Push Notifications often fail on specific Android phones, learn why.
Neil Mathew
Brian Rinaldi recommends
Updating Your App for iOS 11 — An overview of the changes required in order to update your app for iOS 11.
Doron Katz
Brian Rinaldi recommends
An Introduction to Native Android and iOS Development with NativeScript
Nic Raboy


by via Mobile Dev Weekly

How to Use Influencer Marketing to Amplify Your Message

Wondering if social media influencers can increase your company’s reach? Looking for tips to find and evaluate potential influencers for a professional fit? In this article, you’ll discover how all businesses, even B2Bs, can partner with influencers to elevate their messaging. Influencer Marketing Can Work for B2B Companies B2Bs often look at how consumer brands [...]

This post How to Use Influencer Marketing to Amplify Your Message first appeared on .
- Your Guide to the Social Media Jungle


by Tom Augenthaler via