Now is the Time to Learn Functional Programming !


What is Functional Programming?

Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and application state flows through pure functions. Contrast with object oriented programming, where application state is usually shared and collocated with methods in objects. It is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time.
Functional code tends to be more concise, more predictable, and easier to test than imperative or object oriented code but if you’re unfamiliar with it and the common patterns associated with it, functional code can also seem a lot more dense, and the related literature can be impenetrable to newcomers. Some of the popular functional programming languages include: Lisp, Python, Erlang, Haskell, Clojure, Java etc.

Functional programming languages are categorized into two groups, i.e. 
Pure Functional Languages:- These types of functional languages support only the functional paradigms. For example − Haskell.
Impure Functional Languages:-  These types of functional languages support the functional paradigms and imperative style programming. For example − LISP.

Functional Programming Characteristics:

  • Function Closure Support
  • Higher-order functions
  • Use of recursion as a mechanism for flow control
  • No side-effects
  • A focus on what is to be computed rather then how to compute it
  • Referential transparency

Functional Programming Features:

First-Class Functions:- It means that you can store functions into a variable. i.e.

var add = function(a, b){
return a + b
}

High-Order Functions:- It means that functions can return functions or receive other functions as parameters. i.e.

var add = function(a){
return function(b){
return a + b
}
}

var add2 = add(2)
add2(3) // => 5

Pure Functions:- Pure Functions mean that the function doesn’t change any value, it just receives data and output data, just like our beloved functions from Mathematics. That also means that if you’d pass 2 for a function f and it returns 10, it’ll always return 10. Doesn’t it matter the environment, threads, or any evaluation order. They don’t cause any side-effects in other parts of the program and it’s a really powerful concept.

Closures:- Closures mean that you can save some data inside a function that’s only accessible to a specific returning function, i.e the returning function keeps its execution environment.

var add = function(a){
return function(b){
return a + b
}
}

var add2 = add(2)
add2(3) // => 5

Immutable State:- Immutable State means that you can’t change any state at all (even though you can get a new state).

Advantage of Functional Programming

  • Easier to write parallel code. The reason is immutable data structures.
  • More powerful expressions making the code more terse. Monoids, functors, lambdas to name a few.
  • Extensive type checking and a very powerful type system (in typed ones).
  • Homoiconicity in languages like LISP, which makes writing DSLs extremely easy.

Functional Programming v/s Object Oriented Programming

Functional Programming OOP
Uses Immutable data. Uses Mutable data.
Follows Declarative Programming Model. Follows Imperative Programming Model.
Supports Parallel Programming Not suitable for Parallel Programming
Its functions have no-side effects Its methods can produce serious side effects.
Flow Control is done using function calls & function calls with recursion Flow control is done using loops and conditional statements.
Execution order of statements is not so important. Execution order of statements is very important.

Functional Programming in Python

Python is not a functional programming language, but it is a multi-paradigm language that makes functional programming easy to perform, and easy to mix with other programming styles. Lets see the example of calculating total sum of values in a list. In this example we are using an imperative style function.
Calculating total sum of values using normal method

def sum_lst(lst):
total = 0
for number in lst:
total += number
return total

As we can see, our function has only one variable called total that is updated on every iteration. This is clearly a case of a mutable variable.

Now lets try a functional approach:

def sum_lst(lst):
if not lst:
return 0
else:
return lst[0] + sum_lst(lst[1:]) # values are returned but no variable is changed

This time we are not updating any variables and are using recursion, which is the functional programming way of doing loops.

Want to learn Python & Django

Gardmore Abbey 5E rerun – Session 2

On the second session of my 5E rerun of Madness at Gardmore Abbey, the group (still just 3 players because of the same 2 absences) further explored the extra-dimensional watchtower. While that struck them with some minor madness effects, they did arrive at the top of the tower and encountered the beholder. Just like the previous group they negotiated a truce with the beholder and helped him (and them) to escape from the tower. While that is a somewhat selfish act to let loose this force of chaotic evil on the world, this second group had a better excuse: In 4E the beholder on top of the tower is designed to be tough but beatable. In 5E it is a standard beholder from the Monster Manual, with a challenge rating of 13, and thus near impossible for 3 level 5 players to beat.

With the beholder were a group of dazed zombies, one of them an elf zombie. They recognized that one as the lost father of Berrian Velfarren, and could thus finish a quest. Another quest done was scouting the layout of the abbey and number of orcs from the top of the watchtower. So they first passed by the elves, and then from there went back to Winterhaven, to hand in their quest and recover from the madness effects.

Berrian gave them another quest to explore the wizard’s tower. Lord Padraig had another quest to negotiate peace with the elves. And in Winterhaven they encountered a paladin of Bahamut called Sir Oakley, who asked them to accompany him to the temple on top of the abbey to purify it from evil. With thus lots of options they decided to pass by the elves for the peace negotiations, which were easy with them having already done so many quests for the elves. From there they went up to Dragon’s Roost and entered the temple. In the temple were two very strange angel-like creatures, which turned out to be harpies gone mad. Unlike the beholder before the harpies stats were changed to adjust the difficulty of the fight to make it interesting, as standard harpies are only challenge rating 1. With modified abilities causing some nasty effects in a zone around them through singing the fight was quite interesting.

Besides the card they started with, in this session they received 3 cards from the beholder, and 1 card from the harpies. They still haven’t really found out how to control the magical effects from the cards, but then there was only one real combat this session.

Google Pixel 2 and Pixel 2 XL headphone adapter not working for some folks

The Google Pixel 2 series has already seen one significant audio problem, that being related to how it was recorded through the microphone. Though that was fixed in a recent software update, there appears to be another, more persistent, sound issue affecting devices.

Some people Pixel 2 and Pixel 2 XL owners are reporting that the supplied USB Type-C to 3.5 mm headphone jack adapter isn’t working. This was pointed out by users over at the Google Product Forums (via Android Police), and the issue seems to be that the headphone adapter isn’t being recognized: when connected, music still plays through the device speakers.

Editor’s Pick

According to reports, several people have experienced this problem and have contacted Google for a replacement adapter. Others are seeking software solutions, though there doesn’t appear to be a single workaround that applies in every scenario.

One person said that a software update had resolved the issue, while the process below was also offered as a fix:

  • Insert dongle/adapter into phone
  • Restart phone
  • Plug headphones into dongle/adapter
  • Start Google Play Music [and, presumably, play something]

Given that there are a variety of possible solutions, here, it looks like it’s not specifically tied to a faulty adapter (one user says they’ve owned three different dongles and the problem has persisted); there may be more than one problem at play.

Google must be aware of this by now — there are lots of comments and replacement requests have been made — though an employee is yet to step into the thread to discuss the problem directly.

If you’ve experienced this issue, perhaps try using Bluetooth headphones (should you own some) while you wait for this to get sorted out.

Sean Hannity Has a Long, Shady History of Deceptively Editing Videos

The Fox News’ host latest attack on CNN is part of a much broader pattern.

On December 11, Fox News host Sean Hannity aired an edited quote from CNN analyst Paul Callan regarding Wikileaks and Donald Trump Jr. in order to label CNN as “fake news.” This is not the first time Hannity has deceptively edited clips to attack his perceived opponents.

During his December 11 show, Hannity aired a portion of a CNN segment about the network’s report that claimed that during the presidential campaign, Trump Jr. received an email providing website and login information for Hillary Clinton’s hacked campaign emails from Wikileaks. CNN later corrected some parts of its initial report. As reported by Mediaite, Hannity aired a part of the CNN segment on the report that implied Callan said Trump Jr. violated federal and New York state laws. But Callan’s full comment shows that he was speaking hypothetically, and actually said there was not enough evidence for a criminal case against Donald Trump Jr.

Hannity has a history of airing deceptively edited video clips to go after his perceived enemies. In 2011, CNN host Anderson Cooper called him out for clipping Cooper’s words out of context to make his straightforward report on former diplomat Joseph Wilson seem like an attack against the administration of former President George W. Bush. In that same episode, Hannity also deceptively edited clips from journalist Katie Couric and former CBS correspondent Mike Wallace.

Hannity also aired deceptive edits to attack then-President Barack Obama. In 2010, now-Fox host Howard Kurtz criticized Hannity for cropping an Obama speech, making it seem like Obama said that he was raising taxes  when he was actually saying that the Bush administration had planned for the tax increase to occur after Bush left office.  A year before that, Hannity aired clips from a Fox News interview with Obama, editing out specific lines in order to make it seem as if Obama had not acknowledged the role U.S. presidents played in lifting the Iron Curtain. Hannity’s deceptive edits and misrepresentations of Obama’s comments were part of his extensive anti-Obama, conservative disinformation campaign during Obama’s presidency.

In addition to clipping videos to fit his narrative agenda, Hannity has also promoted deceptively edited videos from discredited and fringe sources like James O’Keefe’s ACORN videos, Center for Medical Progress’ false attacks against Planned Parenthood, and filmmaker Ami Horowitz’s anti-Islam YouTube stunt. Hannity’s history of pushing disinformation and conspiracy theories has led to an exodus of advertisers from his Fox News program, adding to a significant drop in the network’s ad revenue. Media Matters has continued to urge Hannity’s advertisers to reconsider funding Hannity’s brand of disinformation and extremism, warning that his volatility makes him a business risk.

 

 

Related Stories

  • Rupert Murdoch Seems to Have Forgotten That He Fired Bill O’Reilly
  • Sean Hannity Has a Long, Revolting History of Undermining Women Who Report Sexual Abuse
  • Sean Hannity’s Heinous Defense of Roy Moore Is in a Class of Its Own

Deal: Xiaomi discounts Mi MIX 2, Mi A1 Special Edition, Redmi Note 4 in “No. 1 Fan Sale”

Xiaomi is celebrating the end of a banner year in the Indian market with a “No. 1 Fan Sale” that applies some tasty discounts to its top phones from 2017. The deals begin to go live at 12:00 am IST and run until December 21st on Mi.com.

The headline deal coincides with the launch of the stunning red Xiaomi Mi A1 Special Edition, which is set to drop from Rs. 13,999 to Rs. 12,999. The offer goes live in just under six hours (at time of writing), but Reward Mi members can get in on the savings early. You can find out all you need to know about the Android One phone here.

On the flagship front, the Xiaomi Mi MIX 2 will enjoy a price drop from Rs. 35,999 to Rs. 32,999 (check here for a refresher on Xiaomi’s bezel-less beauty in our full review) . The Mi Max 2 phablet, meanwhile will come down to Rs. 12,999 from Rs. 14,999.

Xiaomi’s real success in India has come from mid-tier phones, so it’s not too surprising to see the Redmi 4, Redmi Y1 Lite, and the insanely popular Redmi Note 4 all receive price cuts too. Unfortunately, Xiaomi is being a little coy with the finer details on these deals – most only say “up to $1,000 off” – and it hasn’t confirmed which exact models are on offer. I imagine we’re looking at the standard base models, but we won’t know for sure until the sale goes live.

If you’re happy with your current phone but are looking for something on the side then you’re also in luck as Xiaomi’s “Fan Sale” covers accessories too. This includes offers on phone cases, up to 25% off a Mi Power Bank 2i, and the Mi Band – HRX Edition for Rs. 1,299 (was Rs. 1,799). There are also various deals on Xiaomi audio and smart home devices, while the Mi VR Play 2 drops from Rs. 1,499 to Rs. 1,299.

You can see all the deals for yourself by clicking the button below.

Xiaomi No.1 Fan Sale at Mi.com

Unbelievable Censorship: Trump Bans CDC from Using These 7 Words

The forbidden words include “vulnerable,” “diversity,” and “science-based.”

Donald Trump’s administration has reportedly banned the Center for Disease Control from using seven words and phrases, including “science-based” and “transgender,” in documents it is working on for next year’s budget.

 

Related Stories

  • Fate of the Earth Considered Again
  • Women Are Often Caught in a Double Bind: And the Inner Voice of Doubt Can Be a Problem
  • ALEC Backs Extreme Climate Denial, Constitutional Rewrite and Corporate Lobbyists

Which phone manufacturer had the best year in 2017? [Poll of the Week]

Last week’s poll summary: Out of almost 23,800 total votes, 25.1% of our readers said the Galaxy Note 8 is the best Android smartphone of 2017. 18.9% voted for the OnePlus 5T, 18.2% voted Pixel 2 XL, and 11.3% said the Huawei Mate 10 Pro is the top device of the year.

2017 brought us some of the best smartphones we’ve ever seen. It was also the year that we saw many Android OEMs come into their own.

Samsung had a particularly tough year, as it not only had to recover from the Galaxy Note 7 recall, it also had to win the trust back of consumers. Samsung worked hard to bring trust back to its brand, which resulted in the Galaxy S8 and Note 8— two of the best Android smartphones ever made.

OnePlus has also stepped things up this year, particularly with the launch of the OnePlus 5T. The OnePlus 5 felt a little stuck in the past, but the 5T brought an improved camera experience and a fantastic 18:9 OLED display. OnePlus continues to make improvements every year. It’s crazy to think this is the same company that had so many weird missteps a few years back.

See also

Huawei made some huge strides in 2017 with the launch of the Mate 10 Pro. Not only did that phone win our Best of Android 2017 competition, it feels like Huawei is becoming more original than ever before. Some might complain of Huawei’s software being too aggressive in some areas, but the improvements on the design/build front cannot be overstated.

I’d also like to mention HMD Global, the proud owners of the Nokia brand name. The Nokia 8, the company’s 2017 flagship, holds its own against the other competitors on the market. Android Authority actually named HMD Global as the best smartphone brand of 2017.

In your opinion, which smartphone manufacturer had the best year? Cast your vote in the poll below, and speak up in the comments if there’s anything you’d like to add.

Note: There is a poll embedded within this post, please visit the site to participate in this post’s poll.

One more 7th Continent post before I shut up :)

The 2nd Kickstarter for 7th Continent ended with 43,733 backers having pledged over $7 million. But if you missed it, there is a possibility to Late Pledge with options limited to getting either just the new expansion, or the whole game plus expansion. I don’t know how long this will be possible, I presume it is until the pledge manager goes live in November.

*Spoiler Alert*
My wife and me are making great progress on the first curse, The Voracious Goddess. We lost on the first attempt and restarted. Knowing the starting island better made things easier, so on the second attempt we managed to get off the island the comfortable way. That gives you a choice of three places to continue, and by pure chance we seem to have chosen the absolutely best one. We found a place to rest and spend our xp on advanced skills. We found a place to hunt and recover all of the adventuring deck. And we found the next two landmarks on the clue map.

It was getting nearly too easy, and so we decided to do something more risky. Instead of following the clue map further, we entered what I can only describe as a dungeon. We didn’t completely clear it out, because there was a rather suspicious lever we didn’t dare to pull. But we did everything else in it and exited with some treasure and more advanced skills. Next we will try to hunt again and then follow the path on the clue map.

SailCraft Online

The game of Battleship as played with pen and grid paper is a hundred years old. 50 years ago Milton Bradley turned it into a board game with plastic pegs. There have been various computer versions, and even a rather horrible movie in 2012. Now I found a mobile game called SailCraft or SailCraft Online, which is basically Battleship on speed with all modern Pay2Win conveniences.

The original game is strictly symmetrical, except for the player moving first having a slight advantage. But in SailCraft the two players don’t have the exact same fleet, nor do they even have the same size of grid. Instead your grid size and your special abilities depend on the ships you choose for your fleet, limited by the level of your mothership. Ships come in common, uncommon, rare and legendary types, and the more of the same ship you find, the higher you can upgrade them in level. Each ship has an active and a passive ability, and stats for how many spaces it adds to your grid and how much “luck” you have going first. Active abilities allow you to do different things than just targeting space D4 and hoping you hit the battleship: For example you can fire a torpedo, send out a bomber, or use a telescope to scout some grid spaces. There are also counter-abilities like a torpedo-net or anti-aircraft guns.

Overall that makes the game a lot more dynamic to play than the original. But obviously the player who has collected more powerful ships has a distinctive advantage, having more powerful active abilities and a larger grid on which to hide his ships. Fortunately there is a matchmaking system that prevents you getting paired against the top players while you are still in the lower leagues. Which makes the game okay playable without paying any money, or just buying the occasional special offer. Having endless amount of time isn’t much help, as you can only grind a certain number of chests full of ships every day.

I don’t think there is any game left that didn’t get this sort of monetization make-over in a mobile version, frequently based around collectible items. I’ve even seen coin dozer games that work like that. SailCraft has the advantage that the underlying game of Battleship is a relatively intelligent one, and you can actually outthink your opponent to a certain degree. I just don’t think I’ll ever make it to the very top, because that appears to require some serious spending, which I am not willing to do.

World of Warcraft today

I got a “gift” from Blizzard, 7 days of free subscription to WoW. Not that I would have needed it, I still have several tokens I could exchange for game time. But it did what it was supposed to do, prompt me to update the client and play World of Warcraft for an hour or so. Unfortunately for Blizzard that didn’t get me hooked again. Instead I got rather bored with running errands, aka quests, and logged out again.

One major difficulty I have with World of Warcraft is that the buttons I have for each character have changed so often over the life of this game. Which means that even on my main character which I have played literally for thousands of hours I can’t remember the optimum sequence of button presses after a year and a half of not playing the game. That doesn’t appear to matter for quests, I can do those with just randomly mashing buttons, but it is a serious barrier to re-entry if I wanted to play again.

The next thing that hit me was getting billions of artifact points thrown at me for doing not much. It basically made all the effort I had previously put into artifact weapons seem pointless. On the other hand, I had stopped playing with only part 1 of the achievement necessary for flying done, and it turns out that part 2 still needs weeks of grinding to get to. No thanks!

In summary, World of Warcraft has changed the details frequently (which makes it hard to remember how to play well), while not changing the basic structure of the game enough (which makes it hard to find a renewed interest in playing). I still don’t think I will buy the next expansion, Battle for Azeroth.