A press release is a brief news story directed at members of the media announcing something that is newsworthy.
Press releases are often referred to as:
• News Releases
• Media Releases
• Press Statements
• Video Releases
A press release is an official statement distributed to media outlets, written with the intention to compel the reporters to:
• Seek more information
• Cover an event or circumstance
• Write an article or story
Writing a Press Release
An effective press release announces content that is newsworthy: current, relevant information of interest to the target audience. Not all stories are newsworthy, which makes determining the importance of an event crucial. This can be accomplished by answering the following questions:
• What is the story?
• Who does the story affect? Who does it benefit?
• Where is it happening?
• When is the timing of the story? (Does the timing add significance?)
• How did this story come about?
• Why is this story newsworthy? Why is it important?
Remember the following when drafting a press release:
• The target audience dictates the angle of the story. If there are multiple audiences, consider multiple drafts of the same release.
• Keep the press release to one page by eliminating repetitive or non-essential information. Use concise sentences.
• Do not write the press release in the first person (i.e. “We will hold a clinic…”) Write in the third person (i.e. “The ABC League will hold a clinic…”)
You do not have to be a public relations professional to write a press release, and you do not have to pay a writer. Please find below a basic press release template and example:
1.Letterhead/Logo: Include your organization’s logo at the top of the press release to help identify the organization to the media.
2.Contact Information: Designate a contact person to field questions about the release.
3.“For Immediate Release”: Immediate release means that anyone can share the information as soon as the release is made public.
4.Headline/sub-headline: A succinct statement about the story to create interest. The sub-headline describes the headline in a little bit more detail.
5.Dateline: The release date, as well as the city and state where the press release originated. Will precede the first body paragraph.
6.Body: Provide the who, what, when, where, why and how of the story. Additional paragraphs will explain in further detail. A few important notes:
• Summarize the subject and purpose of the announcement.
• Use concise sentences.
• State the facts.
• Include a call to action. Examples: “Call XXX-XXXXX to register.” “All are welcome to attend.” “Donate online at www.xxxxx.com.”
7.Quote: Add quotes from a representative of your organization and other partners.
8.Boilerplate: A boilerplate is standard background information about a company, organization or individual. Learn how to write a boilerplate.
9.Close: The symbol ‘###’ has traditionally been used at the end of the press release to indicate to media that the release has ended.
Distributing a Press Release
Getting a press release into the right hands is essential. In addition to the local newspaper sports section, consider other news sections at the newspaper as well as local TV, radio stations and local bloggers:
• Family & Kids
• Lifestyle
• Features
• Things to Do/Events/Community Calendar
In addition to distributing the release to the local media, distribute the release in other ways:
• Post the press release on your organization’s website and social media.
• Email the release to your internal database, sponsors, donors and partners.
• Email the release to the directors of local youth service agencies and community centers.
• Email the release to school principals and athletic directors.
Keep in mind the following tips in the distribution process:
• Quality over quantity. Sending press releases too often can result in content losing value. One or two engaging releases is better than 10 bland ones.
• Build relationships with reporters. Know their work, be respectful of their time, and interact face-to-face if possible. Build relationships with members of the local media.
• Consider the publications. Target publications — such as blog and magazines — that are have your desired audience.
Suggested Topics
As a youth baseball/softball organization or team, the distribution of a press release may be worthwhile to announce:
• Field renovation or construction projects
• Fundraising projects or events
• Introduction of a new program (age group, division, etc.)
• New or redesigned website
• New sponsorships and partnerships
• Noteworthy news — retirement, new personnel, anniversaries
• Organization charitable contributions or community service projects
• Promotion of upcoming tournaments or games
• Receiving an award, player award winners
• Schedules — program registration dates, tryouts, start/end of season
• Scholarship opportunities for participants
• Skills clinics, camps or seminars (field maintenance, coaching, etc.)
• Volunteer opportunities
In conclusion, a press release can be an effective and low-cost way to promote your organization’s good work and services and to reach potential participants, donors and sponsors. Drafting and distributing a professional, concise press release is well-worth the time.
Here’s how you can make better use of JavaScript arrays
Quick read, I promise. Over the last few months, I noticed that the exact same four mistakes kept coming back through the pull requests I checked. I’m also posting this article because I’ve made all these mistakes myself! Let’s browse them to make sure we correctly use Array methods!
Replacing Array.indexOf with Array.includes
“If you’re looking for something in your Array, use Array.indexOf.” I remember reading a sentence like this one in my course when I was learning JavaScript. The sentence is quite true, no doubt!
Array.indexOf “returns the first index at which a given element can be found,” says the MDN documentation. So, we use the returned index later in our code, and Array.indexOf is the solution.
But, what if we only need to know if our array contains a value or not? Seems like a yes/no question, a boolean question I would say. For this case, I recommend using Array.includes which returns a boolean.
Array.filter is a very helpful method. It creates a new array from another one with all items passing the callback argument. As indicated by its name, we must use this method for filtering, and for getting a shorter array.
But, if we know our callback function can return only one item, I would not recommend it — for example, when using a callback argument filtering through a unique ID. In this case, Array.filter would return a new array containing only one item. By looking for a specific ID, our intention may be to use the only value contained in the array, making this array useless.
Let’s talk about the performance. To return all items matching the callback function, Array.filter must browse the entire array. Furthermore, let’s imagine that we have hundreds of items satisfying our callback argument. Our filtered array would be pretty big.
To avoid these situations, I recommend Array.find. It requires a callback argument like Array.filter, and it returns the value of the first element satisfying this callback. Furthermore, Array.find stops as soon as an item satisfies the callback. There is no need to browse the entire array.
I admit I’ve made this mistake many times. Then, a kind friend told me to check the MDN documentation for a better way. Here’s the thing: this is very similar to our Array.indexOf/Array.includes case above.
In the previous case, we saw Array.find requires a callback as an argument and returns an element. Is Array.find the best solution if we need to know whether our array contains a value or not? Probably not, because it returns a value, not a boolean. With an array containing objects, Array.find would return an entire object while we may only need a boolean. This could cause performance issues.
For this case, I recommend using Array.some which returns the needed boolean.
Using Array.reduce instead of chaining Array.filter and Array.map
Let’s face it, Array.reduce isn’t simple to understand. It’s true! But, if we run Array.filter, then Array.map it feels like we’re missing something, right?
I mean, we browse the array twice here. The first time to filter and create a shorter array, the second time a create a new array (again!) containing new values based on the ones we obtained from Array.filter. To get our new array, we used two Array methods. Each method has its own callback function and an array that we cannot use later — the one created by Array.filter.
To avoid low performances on this subject, my advice is to use Array.reduce instead. Same result, better code! Array.reduce allows you to filter and add the satisfying items into an accumulator. As an example, this accumulator can be a number to increment, an object to fill, a string or an array to concat.
In our case, since we’ve been using Array.map, I recommend using Array.reduce with an array to concat as an accumulator. In the following example, depending on the value for env, we will add it into our accumulator or leave this accumulator as is.
Hope this helps. Be sure to leave comments if you have any thoughts on this article or have any other use cases to show. And if you found it helpful, give me some claps ?. Thanks for reading!
Learn the basics of the JavaScript module system and build your own library
Lately we all have been hearing a lot about “JavaScript Modules”. Everyone is likely wondering what to do with them, and how do they even play a vital role in our daily lives…?
So what the heck is the JS module system? ?
As JavaScript development gets more and more widespread, namespaces and dependencies get much more difficult to handle. Different solutions have been developed to deal with this problem in the form of module systems.
Why is understanding the JS Module System important?
Let me tell you a story.
Telling stories is as basic to human beings as eating. More so, in fact, for while food makes us live, stories are what make our lives worth living – Richard Kearney
Why am I even talking about all this stuff?
So, my day job is to design and architect projects, and I quickly realized that there were many common functionalities required across projects. I always ended up copy-pasting those functionalities to new projects over and over again.
The problem was that whenever one piece of the code changed, I needed to manually sync those changes across all my projects. To avoid all these tedious manual tasks, I decided to extract the common functionalities and compose an npm package out of them. This way, others on the team would be able to re-use them as dependencies and simply update them whenever a new release was rolled out.
This approach had some advantages:
If there was some change in the core library, then a change only had to be made in one place without refactoring all the applications’ code for the same thing.
All the applications remained in sync. Whenever a change was made, all the applications just needed to run the “npm update” command.
Source code of library
So, next step was to publish the library. Right? ?
This was the toughest part, because there were a bunch of things bouncing around in my head, like:
How do I make the tree shakeable?
What JS module systems should I target (commonjs, amd, harmony).
Should I transpile the source?
Should I bundle the source?
What files should I publish?
Everyone of us has had these kind of questions bubbling in our heads while creating a library. Right?
I’ll try to address all the above questions now.
Different Types of JS Module Systems ?
1. CommonJS
Implemented by node
Used for the server side when you have modules installed
No runtime/async module loading
import via “require”
export via “module.exports”
When you import you get back an object
No tree shaking, because when you import you get an object
No static analyzing, as you get an object, so property lookup is at runtime
You always get a copy of an object, so no live changes in the module itself
Poor cyclic dependency management
Simple Syntax
// File log.js
function log(){
console.log('Example of CJS module system');
}
// expose log to other modules
module.exports = { log }
// File index.js
var logModule = require('./log');
logModule.log();
CommonJS Example
2. AMD: Async Module Definition
Implemented by RequireJs
Used for the client side (browser) when you want dynamic loading of modules
Import via “require”
Complex Syntax
// File log.js
define(['logModule'], function(){
// export (expose) foo for other modules
return {
log: function(){
console.log('Example of AMD module system');
}
};
});
// File index.js
require(['log'], function (logModule) {
logModule.log();
});
AMD Example
3. UMD: Universal Module Definition
Combination of CommonJs + AMD (that is, Syntax of CommonJs + async loading of AMD)
Can be used for both AMD/CommonJs environments
UMD essentially creates a way to use either of the two, while also supporting the global variable definition. As a result, UMD modules are capable of working on both client and server.
// File log.js
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
global.log = mod.exports;
}
})(this, function (exports) {
"use strict";
function log() {
console.log("Example of UMD module system");
}
// expose log to other modules
exports.log = log;
});
UMD Example
4. ECMAScript Harmony (ES6)
Used for both server/client side
Runtime/static loading of modules supported
When you import, you get back bindings value (actual value)
Import via “import” and export via “export”
Static analyzing — You can determine imports and exports at compile time (statically) — you only have to look at the source code, you don’t have to execute it
Tree shakeable, because of static analyzing supported by ES6
Always get an actual value so live changes in the module itself
Better cyclic dependency management than CommonJS
// File log.js
const log = () => {
console.log('Example of ES module system');
}
export default log
// File index.js
import log from "./log"
log();
Harmony/ES Example
So now you know all about different types of JS module systems and how they have evolved.
Although the ES Harmony module system is supported by all the tools and modern browsers, we never know when publishing libraries how our consumers might utilize them. So we must always ensure that our libraries work in all environments.
Let’s dive in deeper and design a sample library to answer all the questions related to publishing a library in the proper way.
I’ve built a small UI library (you can find the source code on GitHub), and I’ll share all my experiences and explorations for transpiling, bundling, and publishing it.
Directory Structure
Here we have a small UI library which has 3 components: Button, Card, and NavBar. Let’s transpile and publish it step by step.
Best practices before publishing ?
Tree Shaking ?
Tree shaking is a term commonly used in the context of JavaScript for dead-code elimination. It relies on the static structure of ES2015 module syntax, that is, import and export. The name and concept have been popularized by the ES2015 module bundler rollup.
Webpack and Rollup both support Tree Shaking, meaning we need to keep certain things in mind so that our code is tree shakeable.
// File shakebake.js
const shake = () => console.log('shake');
const bake = () => console.log('bake');
//can be tree shaken as we export as es modules
export { shake, bake };
// File index.js
import { shake } from './shakebake.js'
// only shake is included in the output
// File shakebake.js
const shake = () => console.log('shake');
const bake = () => console.log('bake');
//cannot be tree shaken as we have exported an object
export default { shake, bake };
// File index.js
import { shake } from './shakebake.js'
// both shake and bake are included in the output
Tree Shaking Example
2. Publish all module variants
We should publish all the module variants, like UMD and ES, because we never know which browser/webpack versions our consumers might use this library/package in.
Even though all the bundlers like Webpack and Rollup understand ES modules, if our consumer is using Webpack 1.x, then it cannot understand the ES module.
The main field of the package.json file is usually used to point to the UMD version of the library/package.
You might be wondering — how can I release the ES version of my library/package? ?
The module field of the package.json is used to point to the ES version of the library/package. Previously, many fields were used like js:next and js:main , but module is now standardized and is used by bundlers as a lookup for the ES version of the library/package.
Less well-known fact: Webpack uses resolve.mainfields to determine which fields in package.json are checked.
Performance Tip: Always try to publish the ES version of your library/package as well, because all the modern browsers now support ES modules. So you can transpile less, and ultimately you’ll end up shipping less code to your users. This will boost your application’s performance.
So now what’s next? Transpilation or Bundling? What tools should we use?
Ah, here comes the trickiest part! Let’s dive in. ?
Webpack vs Rollup vs Babel?
These are all the tools we use in our day to day lives to ship our applications/libraries/packages. I cannot imagine modern web development without them — #blessed. Therefore, we cannot compare them, so that would be the wrong question to ask! ❌
Each tool has it’s own benefits and serves different purpose based on your needs.
Let’s look at each of these tools now:
Webpack
Webpack is a great module bundler ? that is widely accepted and mostly used for building SPAs. It gives you all the features out of the box like code splitting, async loading of bundles, tree shaking, and so on. It uses the CommonJS module system.
PS:Webpack-4.0.0 alpha is already out ?. Hopefully with the stable release it will become the universal bundler for all types of module systems.
RollupJS
Rollup is also a module bundler similar to Webpack. However, the main advantage of rollup is that it follows new standardized formatting for code modules included in the ES6 revision, so you can use it to bundle the ES module variant of your library/package. It doesn’t support async loading of bundles.
Babel
Babel is a transpiler for JavaScript best known for its ability to turn ES6 code into code that runs in your browser (or on your server) today. Remember that it just transpiles and doesn’t bundle your code.
My advice: use Rollup for libraries and Webpack for apps.
Transpile (Babel-ify) the source or Bundle it
Again there’s a story behind this one. ?
I spent most of my time trying to figure out the answer to this question when I was building this library. I started digging out my node_modules to lookup all the great libraries and check out their build systems.
Libraries vs Packages build output comparision
After looking at the build output for different libraries/packages, I got a clear picture of what different strategies the authors of these libraries might have had in mind before publishing. Below are my observations.
As you can see in the above image, I’ve divided these libraries/packages into two groups based on their characteristics:
UI Libraries (styled-components, material-ui)
Core Packages (react, react-dom)
If you’re a good observer ? you might have figured out the difference between these two groups.
UI Libraries have a dist folder that has the bundled and minified version for ES and UMD/CJS module systems as a target. There is a lib folder that has the transpiled version of the library.
Core Packages have just one folder which has the bundled and minified version for CJS or UMD module system as a target.
But why is there a difference in build output of UI libraries and Core Packages? ?
UI Libraries
Imagine if we just publish the bundled version of our library and host it on CDN. Our consumer will use it directly in a<script/> tag. Now if my consumer wants to use just the <Button/> component, they have to load the entire library. Also, in a browser, there is no bundler which will take care of tree shaking, and we’ll end up shipping the whole library code to our consumer. We don’t want this.
<script type="module">
import {Button} from "https://unpkg.com/uilibrary/index.js";
</script>
Now if we simply transpile the src into lib and host the lib on a CDN, our consumers can actually get whatever they want without any overhead. “Ship less, load faster”. ✅
<script type="module">
import {Button} from "https://unpkg.com/uilibrary/lib/button.js";
</script>
Core Packages
Core packages are never utilized via the <script/> tag, as they need to be part of main application. So we can safely release the bundled version (UMD, ES) for these kinds of packages and leave the build system up to the consumers.
For example, they can use the UMD variant but no tree shaking, or they can use the ES variant if the bundler is capable of identifying and getting the benefits of tree shaking.
But…what about our question: should we transpile (Babelify) the source or bundle it? ?
For the UI Library, we need to transpile the source with Babel with the es module system as a target, and place it in lib. We can even host the lib on a CDN.
We should bundle and minify the source using rollup for cjs/umd module system and es module system as a target. Modify the package.json to point to the proper target systems.
"main": "dist/index.js", // for umd/cjs builds
"module": "dist/index.es.js", // for es build
...
}
For core packages, we don’t need the lib version.
We just need to bundle and minify the source using rollup for cjs/umd module system and es module system as a target. Modify the package.json to point to the proper target systems, same as above.
Tip: We can host the dist folder on the CDN as well, for the consumers who are willing to download the whole library/package via <script/> tag.
How should we build this?
We should have different scripts for each target system in package.json . You can find the rollup config in the GitHub repo.
In package.json , the "files" field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. If you name a folder in the array, then it will also include the files inside that folder.
We will include the lib and dist folders in "files" field in our case.
// package.json
{
...
"files": ["dist", "lib"]
...
}
Finally the library is ready to publish. Just type the npm run build command in the terminal, and you can see the following output. Closely look at the dist and lib folders. ?
Ready to publish ?
Wrap up
Wow! Where does the time go? That was a wild ride, but I sincerely hope it gave you a better understanding of the JavaScript Module system and how you can create your own library and publish it.
Just make sure you take care of the following things:
Make it Tree Shakeable. ?
Target at least ES Harmony and CJS module systems. ?
Use Babel and Bundlers for libraries. ?
Use Bundlers for Core packages. ?
Set the module field of package.json to point to the ES version of your module (PS: It helps in tree shaking). ?
Publish the folders which have transpiled as well as bundled versions of you module. ?
avaScript has a reputation for being one of the worst programming languages in existence, and for good reasons! JavaScript is easy to learn and easy to use, except when it’s not. There are many “gotchas” that can trip you up. Below, I glean some of the best from various online sources…
1) There is no integer type! JavaScript has only one numerical type and that’s (double precision) floating point. This is the only language I’ve ever used that doesn’t have an integer type (and I’ve used many). Most of the time, you can get away with it, but there will come a day when it will bite you in the ass. Especially if you need 64-bit integers.
typeof NaN → "number" // NaN is a number??? But...
NaN != NaN → true
NaN !== NaN → true
2) JavaScript’s loose typing and aggressive coercions exhibit odd behaviour.
[] + [] → "" // Empty string? These are arrays!
[] + {} → [object object]
{} + [] → 0 // Why isn't the operation commutative???
{} + {} → NaN // ???
16 == [16] → true // Array converted into string, then into number
16 == [1,6] → false // But what is array converted into?
"1,6" == [1,6] → true
var arr = [];
arr.length → 0
arr[3] → "undefined" // No array bounds exception???
arr[3] = "hi";
arr.length → 4 // 4??? Only one element has been added!
arr["3"] → "hi" // Apparently "3" is coerced into a number
delete(arr[3]);
arr.length → 4 // 4??? There are no elements in the array!
arr[3] → "undefined" // 7 lines above, length was "0"!
var i = 1;
i = i + ""; // Oops!
i + 1 → "11"
i - 1 → 0
var j = "1";
++j → 2 // Okay, but...
var k = "1";
k += 1 → "11" // What???
[1,5,20,10].sort() → [1, 10, 20, 5] // Why is it sorting strings???
This is nonsense. If a language possesses insane semantics, then it is dangerous to use. If it’s difficult to reason about the language, then it is dangerous to use.
Incidentally, ECMA should remove “==” and force everyone to use “===”. Having both is damn confusing.
3) Automatic semicolon insertion. This can cause subtle bugs and unexpected behaviour. Why does this “feature” even exist??? It’s super weird and unnecessary. Get rid of it, ECMA, please!
4) JavaScript is seriously abused. Much of the code in the wild, especially those in commonly used libraries, are very badly written. The authors have abused the language every which way, and we pay for it in terms of performance and/or ability to reason about the code.
Programmers often have to write workarounds for various problems in the language and these workarounds are immensely complex and cumbersome to understand. For example, the module pattern and other attempts to create private scopes with localized state and logic that use closures and functions wrapped in functions, wrapped in functions, are beyond mad. Thankfully, this is fixed in ES6, but I present it as one of many examples that are still widely prevalent.
This is a language issue because JavaScript’s nature makes it easy, and often necessary, to write convoluted, difficult-to-understand code. Peter DiSalvo goes into more details here, and he is quite eloquent!
5) JavaScript is highly dependent on global variables. Implied global variables are especially problematic (“use strict” to avoid). Global variables seriously complicate your programs.
JavaScript also has horrible scoping rules.
6) JavaScript code can fail silently due to syntactical slip-ups. It has happened to me several times, and tracking down the reason can be most exasperating.
7) Object prototypes do not scale well to large applications; it’s a rather primitive and sloppy way to do object-oriented programming (but it’s flexible!). Further, there are multiple ways to handle object inheritance, making it difficult to decide which way to go. JavaScript is the only popular OOP language that uses object prototypes. The preference for class-based OOP is clear, such that ES6 and TypeScript employ classes. Nevertheless, their classes are not as completely fleshed out as you would find in Smalltalk and C++, for example.
And because the use of object prototypes is so poorly understood by most JavaScript developers, they abuse the language and write horrible code as a result.
8) Asynchronous programming in JavaScript is very messy. Callback hell is a frequent complaint. (Promises mitigate this to some extent, but are not a perfect solution.)
9) Douglas Crockford says that JavaScript is “Lisp in C’s Clothing.” Lisp is a wonderful language and by extension, so is JavaScript.
But JavaScript is nothing like Lisp!
JavaScript’s C-like syntax robs it of Lisp’s clean and elegant syntax.
Lisp’s central data structure is the list. JavaScript doesn’t have a list data type. JavaScript’s central data structure is the associative array, which often masquerades as some other data type.
Lisp is homoiconic, i.e., its code and its data have the same primary representation. JavaScript is not. Not even a little bit.
Lisp’s homoiconicity provides for a powerful macro system. JavaScript does not have macros.
Lambdas do not make JavaScript Lisp-like, any more than C++, Java, Python, Haskell, and Smalltalk are Lisp-like.
If you like Lisp, then use Lisp. Use Clojure or ClojureScript. Don’t use JavaScript, which has little reason to exist other than its ubiquity in web browsers.
10) The main draw of JavaScript is actually in frameworks like Node.js and AngularJS. If not for them, why would you use JavaScript??? Prior to 2009, when Node.js was released, people generally avoided using JavaScript; its use was limited to some jQuery and webpage enhancements. Everyone understood that JavaScript was a terrible language, and so it was used only sparingly. But then, someone thought it was a good idea to put this awful language on the server.
The front-end JavaScript landscape is highly fragmented and unstable. Frameworks come and go, depending on current trends and whims. AngularJS was the darling of front-end development for a long while, but suddenly ReactJS came out of nowhere to vie for top spot. This makes it dicey to invest a great deal of time and effort in any one particular framework. (The transition from Angular 1.x to 2.0 has been especially disruptive.)
But why use any of these frameworks, only to inflict JavaScript on yourself? Accept JavaScript as the “assembly language” of the Web and select better tools that “transpile” to it. Use Amber. Use ClojureScript. Use Ceylon. Use GopherJS. Hell, use Dart! Use anything but JavaScript.
And guess what? There’s already a de facto standard web framework that’s been around for ages and is rock-solid, well-supported, and widely used. It’s called jQuery and it’s all you really need to create a terrific UX. It’s supported by every transpiled language. Forget Angular, React, Backbone, Ember, Meteor, Polymer, Mithril, Aurelia, etc., etc. etc. Are you kidding me?!!
JavaScript apologists frequently tout using JSLint as a universal solution to JavaScript’s problems. However, this tool has major limitations. It’s also highly opinionated. Moreover, it’s difficult to incorporate into your workflow, which is why many JavaScript developers do not use it. And finally, JSLint’s output results are subject to interpretation and you need to decide what to do about them; sometimes, you actually want to break the “rules!” This additional cognitive burden only makes your job harder, as if programming wasn’t already hard enough. Is it too much to ask for a programming language that doesn’t have such horrendous problems that I need a tool to help me avoid them?