"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Friday, February 3, 2017
CSS Pseudo-classes: :not() and :target
The following is an extract from our book, CSS Master, written by Tiffany B. Brown. Copies are sold in stores worldwide, or you can buy it in ebook form here. As mentioned earlier in this chapter, pseudo-classes help us define styles for documents based on information that is unable to be gleaned from the document […]
Continue reading %CSS Pseudo-classes: :not() and :target%
by Simon Mackie via SitePoint
Mobile Local Marketing: Reaching the Mobile Customer
Do you have a local business? Want an effective way to market to people who are near you? To explore how to reach your customers with mobile marketing, I interview Rich Brooks. More About This Show The Social Media Marketing podcast is an on-demand talk radio show from Social Media Examiner. It’s designed to help [...]
This post Mobile Local Marketing: Reaching the Mobile Customer first appeared on .
- Your Guide to the Social Media Jungle
by Michael Stelzner via
Thursday, February 2, 2017
Incredible Tips And Tools For Business Blogging
[ This is a content summary only. Visit our website http://ift.tt/1b4YgHQ for full links, other content, and more! ]
by Guest Author via Digital Information World
Java Module System Hands-On Guide
In this post we'll take an existing demo application and modularize it with Java 9. If you want to follow along, head over to GitHub, where all of the code can be found. The setup instructions are important to get the scripts running with Java 9. For brevity, I removed the prefix org.codefx.demo
from all package, module, and folder names in this article.
The Application Before Jigsaw
Even though I do my best to ignore the whole Christmas kerfuffle, it seemed prudent to have the demo uphold the spirit of the season. So it models an advent calendar:
- There is a calendar, which has 24 calendar sheets.
- Each sheet knows its day of the month and contains a surprise.
- The death march towards Christmas is symbolized by printing the sheets (and thus the surprises) to the console.
Of course the calendar needs to be created first. It can do that by itself but it needs a way to create surprises. To this end it gets handed a list of surprise factories. This is what the main
method looks like:
public static void main(String[] args) {
List<SurpriseFactory> surpriseFactories = Arrays.asList(
new ChocolateFactory(),
new QuoteFactory()
);
Calendar calendar =
Calendar.createWithSurprises(surpriseFactories);
System.out.println(calendar.asText());
}
The initial state of the project is by no means the best of what is possible before Jigsaw. Quite the contrary, it is a simplistic starting point. It consists of a single module (in the abstract sense, not the Jigsaw interpretation) that contains all required types:
- "Surprise API" - Surprise and
SurpriseFactory
(both are interfaces) - "Calendar API" -
Calendar
andCalendarSheet
to create the calendar - Surprises - a couple of
Surprise
andSurpriseFactory
implementations - Main - to wire up and run the whole thing.
Compiling and running is straight forward (commands for Java 8):
# compile
javac -d classes/advent ${source files}
# package
jar -cfm jars/advent.jar ${manifest and compiled class files}
# run
java -jar jars/advent.jar
Entering Jigsaw Land
The next step is small but important. It changes nothing about the code or its organization but moves it into a Jigsaw module.
Modules
So what's a module? To quote the highly recommended State of the Module System:
A module is a named, self-describing collection of code and data. Its code is organized as a set of packages containing types, i.e., Java classes and interfaces; its data includes resources and other kinds of static information.
To control how its code refers to types in other modules, a module declares which other modules it requires in order to be compiled and run. To control how code in other modules refers to types in its packages, a module declares which of those packages it exports.
(The last paragraph is actually from an old version of the document but I like how it summarizes dependencies and exports.)
So compared to a JAR a module has a name that is recognized by the JVM, declares which other modules it depends on and defines which packages are part of its public API.
Name
A module's name can be arbitrary. But to ensure uniqueness it is recommended to stick with the inverse-URL naming schema of packages. So while this is not necessary it will often mean that the module name is a prefix of the packages it contains.
Dependencies
A module lists the other modules it depends on to compile and run. This is true for application and library modules but also for modules in the JDK itself, which was split up into about 100 of them (have a look at them with java --list-modules
).
Again from the design overview:
When one module depends directly upon another in the module graph then code in the first module will be able to refer to types in the second module. We therefore say that the first module reads the second or, equivalently, that the second module is readable by the first.
[...]
The module system ensures that every dependence is fulfilled by precisely one other module, that the module graph is acyclic, that every module reads at most one module defining a given package, and that modules defining identically-named packages do not interfere with each other.
When any of the properties is violated, the module system refuses to compile or launch the code. This is an immense improvement over the brittle classpath, where e.g. missing JARs would only be discovered at runtime, crashing the application.
It is also worth to point out that a module is only able to access another's types if it directly depends on it. So if A depends on B, which depends on C, then A is unable to access C unless it requires it explicitly.
Exports
A module lists the packages it exports. Only public types in these packages are accessible from outside the module.
This means that public
is no longer really public. A public type in a non-exported package is as inaccessible to the outside world as a non-public type in an exported package. Which is even more inaccessible than package-private types are before Java 9 because the module system does not even allow reflective access to them. As Jigsaw is currently implemented command line flags are the only way around this.
Implementation
To be able to create a module, the project needs a module-info.java
in its root source directory:
module advent {
// no imports or exports
}
Wait, didn't I say that we have to declare dependencies on JDK modules as well? So why didn't we mention anything here? All Java code requires Object
and that class, as well as the few others the demo uses, are part of the module java.base
. So literally every Java module depends on java.base
, which led the Jigsaw team to the decision to automatically require it. So we do not have to mention it explicitly.
The biggest change is the script to compile and run (commands for Java 9):
# compile (include module-info.java)
javac -d classes/advent ${source files}
# package (add module-info.class and specify main class)
jar --create \
--file=mods/advent.jar \
--main-class=advent.Main \
${compiled class files}
# run (specify a module path and simply name to module to run)
java --module-path mods --module advent
We can see that compilation is almost the same - we only need to include the new module-info.java
in the list of classes.
The jar command will create a so-called modular JAR, i.e. a JAR that contains a module. Unlike before we need no manifest anymore but can specify the main class directly. Note how the JAR is created in the directory mods
.
Utterly different is the way the application is started. The idea is to tell Java where to find the application modules (with --module-path mods
, this is called the module path) and which module we would like to launch (with --module advent
).
Splitting Into Modules
Now it's time to really get to know Jigsaw and split that monolith up into separate modules.
Continue reading %Java Module System Hands-On Guide%
by Nicolai Parlog via SitePoint
How to Make Modern PHP More Modern? With Preprocessing!
Let's have a bit of fun. A while ago, I experimented with PHP macros, adding Python range syntax. Then, the talented SaraMG mentioned an RFC, and LordKabelo suggested instead adding C#-style getters and setters to PHP.
Aware of how painfully slow it can be for an outsider to suggest and implement a new language feature, I took to my editor...
The code for this tutorial can be found on Github. It's been tested with PHP
^7.1
, and the generated code should run on PHP^5.6|^7.0
.
How Do Macros Work Again?
It's been a while (and perhaps you've never heard of them) since I've talked about macros. To refresh your memory, they take code that looks like this:
macro {
→(···expression)
} >> {
··stringify(···expression)
}
macro {
T_VARIABLE·A[
···range
]
} >> {
eval(
'$list = ' . →(T_VARIABLE·A) . ';' .
'$lower = ' . explode('..', →(···range))[0] . ';' .
'$upper = ' . explode('..', →(···range))[1] . ';' .
'return array_slice($list, $lower, $upper - $lower);'
)
}
...and turn custom PHP syntax, like this:
$few = many[1..3];
...into valid PHP syntax, like this:
$few = eval(
'$list = ' . '$many' . ';'.
'$lower = ' . explode('..', '1..3')[0] . ';' .
'$upper = ' . explode('..', '1..3')[1] . ';' .
'return array_slice($list, $lower, $upper - $lower);'
);
If you'd like to see how this works, head over to the the post I wrote about it.
The trick is to understand how a parser tokenizes a string of code, build a macro pattern, and then apply that pattern recursively to the new syntax.
The macro library isn't well documented, though. It's difficult to know exactly what the pattern needs to look like, or what valid syntax to generate in the end. Every new application begs for a tutorial like this to be written, before others can understand what's really going on.
Building A Base
So, let's look at the application at hand. We'd like to add getter and setter syntax, resembling that of C#, to PHP. Before we can do that, we need to have a good base of code to work from. Perhaps something in the form of a trait that we can add to classes needing this new functionality.
We need to implement code that will inspect a class definition and create these dynamic getter and setter methods for each special property or comment it sees.
Perhaps we can start by defining a special method name format, and magic __get
and __set
methods:
namespace App;
trait AccessorTrait
{
/**
* @inheritdoc
*
* @param string $property
* @param mixed $value
*/
public function __get($property)
{
if (method_exists($this, "__get_{$property}")) {
return $this->{"__get_{$property}"}();
}
}
/**
* @inheritdoc
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value)
{
if (method_exists($this, "__set_{$property}")) {
return $this->{"__set_{$property}"}($value);
}
}
}
Each method starting with the name __get_
and __set_
needs to be connected to an as-yet undefined property. We can imagine this syntax:
namespace App;
class Sprocket
{
private $type {
get {
return $this->type;
}
set {
$this->type = strtoupper($value);
}
};
}
...being converted to something very much like:
namespace App;
class Sprocket {
use AccessorTrait;
private $type;
private function __get_type() {
return $this->type;
}
private function __set_type($value) {
$this->type = strtoupper($value);
}
}
Defining Macros
Defining the required macros is the hardest part of any of this. Given the lack of documentation (and widespread use), and with only a handful of helpful exception messages, it's mostly a lot of trial and error.
I spent a few hours coming up with the following patterns:
macro ·unsafe {
·ns()·class {
···body
}
} >> {
·class {
use AccessorTrait;
···body
}
}
macro ·unsafe {
private T_VARIABLE·var {
get {
···getter
}
set {
···setter
}
};
} >> {
private T_VARIABLE·var;
private function ··concat(__get_ ··unvar(T_VARIABLE·var))() {
···getter
}
private function ··concat(__set_ ··unvar(T_VARIABLE·var))($value) {
···setter
}
}
Continue reading %How to Make Modern PHP More Modern? With Preprocessing!%
by Christopher Pitt via SitePoint
Meet the Top 3% Disrupting the Freelance Industry
This article is part of an SEO series from Toptal. Thank you for supporting the partners who make SitePoint possible.
As the freelance workforce continues to grow rapidly, so does the struggle for companies to find the right talent to get the job done effectively and efficiently.
Considering the amount of time, effort and money required to find a good freelancer, it’s really no wonder why so many employers dread doing the task. Simply put, it’s no longer about finding a good candidate for a job, but the best candidate - one with the right experience, knowledge and skills that are specific to the needs of your project.
Cue in Toptal — an exclusive, elite network that has curated the top 3% of freelance software developers, UX/UI designers and finance experts in the world as its talent. In other words, they’re a breath of fresh air in an otherwise crowded industry, changing it for the better.
Continue reading %Meet the Top 3% Disrupting the Freelance Industry%
by Aleczander Gamboa via SitePoint