COPY CODE SNIPPET

All contents

Wednesday, 1 November 2017

10 Basic Programming Principles Every Programmer Must Follow

Anyone can write code. But good code? That’s where it gets tough.
We’ve all heard horror stories about spaghetti code, massive if-else chains, entire programs that can break just by changing one variable, functions that look like they were obfuscated, and so on. That’s what happens when you try to make a shippable product with only a semester of programming experience under your belt.
Don’t settle for writing code that works. Aim to write code that can be maintained — not only by yourself, but by anyone else who may end up working on the software at some point in the future. To that end, here are several principles to help you clean up your act.

1. KISS

The “keep it simple, stupid” principle applies to pretty much all of life, but it’s especially necessary in medium-to-large programming projects.
It starts way in the beginning when you’re defining the scope of what you want to create. Just because you’re passionate about game development doesn’t mean you can create the next World of Warcraft or Grand Theft Auto. When you think you’ve simplified enough, simplify it one level further — feature creep is inevitable, so start small.
10 Basic Programming Principles Every Programmer Must Follow programming principle programming
But even after coding has begun, keep it simple. Complex code takes longer to design and write, is more prone to bugs and errors, and is harder to modify later down the road. In the wise words of Antoine de Saint-Exupery, “Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”

2. DRY

The “don’t repeat yourself” principle is crucial for clean and easy-to-modify code. When writing code, you want to avoid duplication of data and duplication of logic. If you notice the same chunk of code being written over and over again, you’re breaking this principle.
The opposite of DRY code is WET code: “write everything twice” (or “waste everyone’s time”). One of the best ways to diagnose WET code is to ask yourself: in order to alter the program’s behavior in some way, how many areas of code would you need to modify?
Suppose you’re writing a podcast directory app. On the search page, you have code for fetching a podcast’s details. On the podcast page, you have code to fetch that podcast’s details. On the favorites page, the same fetching code. Consider abstracting all of that into a function so that if you need to edit it later, you can do it all in one spot.

3. Open/Closed

Whether you’re writing objects in Java or modules in Python, you should aim to make your code open to extension but closed to modification. This applies to all kinds of projects, but is especially important when releasing a library or framework meant for others to use.
For example, suppose you’re maintaining a GUI framework. You could release it as-is, expecting end users to directly modify and integrate your released code. But what happens when you release a major update four months later? How do they implement all of your additions without throwing away all the work they’ve done?
Instead, release code that prevents direct modification and encourages extension. This separates core behavior from modified behavior. The benefits? Greater stability (users can’t accidentally break core behavior) and greater maintainability (users only worry about extended code). The open/closed principle is key to making a good API.What Are APIs, And How Are Open APIs Changing The Internet What Are APIs, And How Are Open APIs Changing The InternetHave you ever wondered how programs on your computer and the websites you visit "talk" to each other?READ MORE

4. Composition > Inheritance

The “composition over inheritance” principle states that objects with complex behaviors should do so by containing instances of objects with individual behaviors rather than inheriting a class and adding new behaviors.
Overreliance on inheritance can lead to two major issues. First, the inheritance hierarchy can become messy in the blink of an eye. Second, you have less flexibility for defining special-case behaviors, particularly when you want to implement behavior from one inheritance branch in another inheritance branch:
10 Basic Programming Principles Every Programmer Must Follow programming principle composition inheritance
Composition is a lot cleaner to write, easier to maintain, and allows for near-infinite flexibility as far as what kinds of behaviors you can define. Each individual behavior is its own class, and you create complex behaviors by combining individual behaviors.

5. Single Responsibility

The single responsibility principle says that every class or module in a program should only concern itself with providing one bit of specific functionality. As Robert C. Martin puts it, “A class should have only one reason to change.”
Classes and modules often start off this way, but as you add features and new behaviors, it’s easy for them to evolve into God classes and God modules that take up hundreds, or even thousands, of lines of code. At this point, you should break them up into smaller classes and modules.

6. Separation of Concerns

The separation of concerns principle is like the single responsibility principle but on a more abstract level. In essence, a program should be designed so that it has many different non-overlapping encapsulations, and these encapsulations shouldn’t know about each other.
A well-known example of this is the model-view-controller (MVC) paradigm, which separates a program into three distinct areas: the data (“model”), the logic (“controller”), and what the end user sees (“view”). Variations of MVC are common in today’s most popular web frameworks.

10 Basic Programming Principles Every Programmer Must Follow programming principle mvc pattern
Image Credit: Wikimedia

For example, the code that handles the loading and saving of data to a database doesn’t need to know how to render that data on the web. The rendering code may take input from the end user, but then passes that input to the logic code for processing. Each part handles itself.
This results in modular code, which makes maintenance much easier. And in the future, if you ever need to rewrite all of the rendering code, you can do so without worrying about how the data gets saved or the logic gets processed.

7. YAGNI

The “you aren’t gonna need it” principle is the idea that you should never code for functionality that you may need in the future. Chances are, you won’t need it and it will be a waste of time — and not only that, but it will needlessly increase your code’s complexity.
You could view this as a specific application of the KISS principle and a response to those who take the DRY principle too seriously. Often inexperienced programmers try to write the most abstract and generic code possible to avoid WET code, but too much abstraction ends up in bloated impossible-to-maintain code.
The trick is to apply the DRY principle only when you need to. If you notice chunks of code being written over and over, then abstract them — but never when you think a piece of code will be written over and over. More times than not, it won’t be.

8. Avoid Premature Optimization

The no premature optimization principle is similar to the YAGNI principle. The difference is that YAGNI addresses the tendency to implement behaviors before they’re necessary while this principle addresses the tendency to speed up algorithms before it’s necessary.
The problem with premature optimization is that you can never really know where a program’s bottlenecks will be until after the fact. You can guess, of course, and sometimes you may even be right. But more often than not, you’ll waste valuable time trying to speed up a function that isn’t as slow as you think or doesn’t get called as often as you’d expect.
Reach your milestones as simply as you can, then profile your code to identify true bottlenecks.

9. Refactor, Refactor, Refactor

One of the hardest truths to accept as an inexperienced programmer is that code rarely comes out right the first time. It may feel right when you implement that shiny new feature, but as your program grows in complexity, future features may be hindered by how you wrote that early one.
10 Basic Programming Principles Every Programmer Must Follow programming principle coding
Codebases are constantly evolving. It’s completely normal to revisit, rewrite, or even redesign entire chunks of code — and not just normal, but healthy to do so. You know more about your project’s needs now than when you did at the start, and you should regularly use this newly gained knowledge to refactor old code.
Note that it doesn’t always have to be a big process. Take a page from the Boy Scouts of America, who live by these words: “Leave the campground cleaner than you found it.” If you ever need to check or modify old code, always clean it up and leave it in a better state.

10. Clean Code > Clever Code

Speaking of clean code, leave your ego at the door and forget about writing clever code. You know what I’m talking about: the kind of code that looks more like a riddle than a solution and exists solely to show off how smart you are. The truth is, nobody really cares.
One example of clever code is packing as much logic into one line as possible. Another example is exploiting a language’s intricacies to write strange but functional statements. Anything that might cause someone to say “Wait, what?” when poring over your code.
Good programmers and readable code go hand in hand. Leave comments when necessary. Adhere to style guides, whether dictated by a language (like Python) or a company (like Google). Observe per-language idioms and stop writing Java code in Python or vice versa. See our article on tips for writing cleaner code.10 Tips for Writing Cleaner & Better Code 10 Tips for Writing Cleaner & Better CodeWriting clean code looks easier than it actually is, but the benefits are worth it. Here's how you can start writing cleaner code today.READ MORE

What Makes a Good Programmer?

Ask five people and you’ll get 10 different answers. To me, a good programmer is one who understands that coding should ultimately serve the end user, who is easy to work with in a team, and who finishes his projects to specification and on time.
If you’re just starting out, don’t worry too much about that yet. Focus on learning how to code without stress. If you feel stuck, see our article on overcoming programmer’s block. And if you just aren’t happy writing code, read our article on signs you aren’t meant to be a programmer.6 Signs That You Are Not Meant To Be A Programmer 6 Signs That You Are Not Meant To Be A Programmer

how transfer photos from android to PC

So you have a Samsung Galaxy series mobile device — perhaps a Galaxy S (smartphone), a Galaxy Tab (tablet), or a Galaxy Note (phablet) — and you’ve just gone on vacation, or went to a concert, or threw a birthday party. You now have a bunch of photos sitting on your device and you want to pull them onto your PC.
What’s the best way to do this?
Actually, there are several methods you can use! And they can all transfer files of all kinds, not just photos, so it’s up to you to choose the one that’s most convenient for you. I’ll be demonstrating on a Galaxy Tab running Android 6.0 Marshmallow.

1. USB

How to Transfer Photos From Your Samsung Phone to Your PC transfer samsung pc usb
We put this method first because it’s the easiest and most likely to work with pretty much any Samsung device. After all, every device uses USB to charge and every modern Windows PC has at least one USB port that you can use.
  1. Connect your Samsung device to your PC using a USB cable.
  2. The first time you do this, device drivers will automatically download and install on your PC. If your system asks for permission to do this, grant it.
  3. On the Samsung device, when asked to Allow access to device data, allow it.
  4. Open File Explorer on your PC and you’ll see the Samsung device as a connected device. You can now use File Explorer to access the device’s file contents, including all of its photos. Photos can be found in the DCIM folder on most devices.

2. External SD Card

If your Samsung device has a slot for an external SD or microSD card, then this method may be preferable to using a USB cable. While some laptops have built-in SD or microSD readers, most computers don’t. But that’s okay! Just buy an adapter like the Anker 8-in-1 Portable Card Reader, which connects via USB.
Portable Card Reader for SDXC, SDHC, SD, MMC, RS-MMC, Micro SDXC, Micro SD, Micro SDHC Card and UHS-I CardsSimultaneously read and write on two cards to save yourself the effort of constant unplugging and re-plugging.
Insert the external card into your device, then use one of these file explorer apps to transfer all of your photos to the card. Remove the card, plug it into the adapter, and you’ll see it on your PC as an external device. You can then pull photos from it using the USB directions above.The 7 Best Free File Explorers for Android The 7 Best Free File Explorers for AndroidThere are a bunch of file management and file exploring apps out there for Android, but these are the best.READ MORE

3. Bluetooth

How to Transfer Photos From Your Samsung Phone to Your PC transfer samsung pc bluetooth
Your Samsung device most likely supports Bluetooth but this method requires a Bluetooth-capable PC as well. Most laptops fit the bill, but some desktops don’t. I do prefer this method over the USB method because it doesn’t involve any cables.6 Top Uses For Bluetooth On Your Android Phone 6 Top Uses For Bluetooth On Your Android PhoneBluetooth has been an impressive wireless technology to enable all sorts of cool functionality with multiple gadgets. While it was rather limited during the early stages of its life, Bluetooth has evolved to be capable...READ MORE
On your Samsung device, pull down the notification panel from the top edge of the screen, then tap Bluetooth to enable it. When the Bluetooth dialog box comes up, tap on your device to make it visible. This will allow your PC to find and connect to it.
On Windows 10, connect to the device with these steps:
  1. Open the Action Center panel (Windows key + A).
  2. In the Action Center, enable Bluetooth if it isn’t already.
  3. Open the Start Menu, search and launch Bluetooth settings.
  4. In the list of visible Bluetooth devices, select your device and click Pair.
  5. A numeric passcode will appear on both. If they match, click Yes on Windows 10 and tap OK on the Samsung device.
  6. When paired, click Send or receive files via Bluetooth, then Receive files.
  7. On the Samsung device, use the My Files app to select all the photos you want to download, then Share them and select Bluetooth as the method, then choose your PC as the destination.
  8. When the file transfer request shows up on the PC, click Finish.

4. FTP Over Wi-Fi

How to Transfer Photos From Your Samsung Phone to Your PC transfer samsung pc wifi ftp
FTP (File Transfer Protocol) is a simple way to transfer files over the internet between a server (in this case, your Samsung device) and a client (the destination PC). To do this, we’ll need to install an app that lets your device become a server and FTP software that allows your PC to connect to the device while the device’s server app is on.
I use a free app called WiFi FTP Server. It’s highly reviewed with 4.5 stars over 2,000+ ratings, it’s easy to use, and it’s regularly updated, but it has non-intrusive ads. Once installed, it’s as easy as tapping the Start button to turn on server mode.
On Windows, we recommend these free FTP clients if you have experience using FTP. If not, then we just recommend using the FTP capabilities of File Explorer instead. This is actually the quickest and easiest way to get started with FTP on Windows. On Mac, here are instructions for using the FTP capabilities of Finder.How to Turn Windows File Explorer Into an FTP Client How to Turn Windows File Explorer Into an FTP ClientWhen you need to move files between computers, FTP is a great way to do it. And if you use Windows File Explorer, you no longer need a third-party FTP client. Here's how...READ MORE
Now that the device and PC are set up, you can transfer photos:
  1. Open WiFi FTP Server and tap Start. Allow permission if asked.
  2. Note the Server URLUserid, and Password, and use them as connection details in your FTP client.
  3. Once connected, you’ll be able to browse the entire contents of the Samsung device through the FTP client. Navigate to the DCIM folder to find camera photos.
  4. Use the FTP client to download those photos to your PC.

5. Cloud Storage Sync

How to Transfer Photos From Your Samsung Phone to Your PC transfer samsung pc cloud
Cloud storage is arguably the easiest way to move files across devices, but it does have a big downside: limited storage space. This doesn’t matter if you only need to pull a handful of photos, but since photos tend to be big, you may have trouble transferring large albums or an entire set of images from a one-month vacation abroad.
First, set up a free account with one of these cloud storage services. Google Drive is your best bet because it provides the largest amount of space for free users at 15GB. You’ll then want to install the Google Drive app on your Samsung device and Google Drive on your PC.Dropbox vs. Google Drive vs. OneDrive: Which Cloud Storage Is Best for You? Dropbox vs. Google Drive vs. OneDrive: Which Cloud Storage Is Best for You?Have you changed the way you think about cloud storage? The popular options of Dropbox, Google Drive, and OneDrive have been joined by others. We help you answer which cloud storage service should you use.READ MORE
On your Samsung device:
  1. Open the Gallery app.
  2. Select all the images you want to transfer, then Share and select Save to Drive.
  3. Select the right Google Drive account (if you’re logged in to more than one), select the folder where you want them saved, then tap Save.
  4. Wait for it to sync.
  5. On your PC, navigate to your Google Drive folder, find where you saved the images, then move them to wherever else you want on your system.

How Do You Transfer Photos

We’ve covered a few methods for transferring photos from a Samsung device to a PC, but it’s up to you to decide which is the most convenient for you.
What’s your favorite way to transfer files between Samsung device and PC? Are there any methods we missed? Let us know in the comments below!

The best backup software for windows

Types of Backup

Backups can be split into two categories: file backups and system backups (also known as system images). File backups create copies of individual files, system backups will make a copy of your entire operating system. System backups are much larger than file backups.
File backups can be further sub-categorized into full backups, differential backups, and incremental backups.
  • Full backups copy all the files on your computer. They are important to perform occasionally, but because so little data on your machine changes between backups, they can be a waste of time and space if you do them all the time.
  • Differential backups copy all changes since you performed the last full backup.
  • Incremental backups copy all the changes since the last backup of any type. They are the most efficient form of backup for most users.

Native Windows Tools

Windows offers native tools for both file backups and system images. At the time of writing, the process is somewhat disjointed. It uses both the Settings app and the Control Panel. Presumably, it will be streamlined in future updates.The Ultimate Windows 10 Data Backup Guide The Ultimate Windows 10 Data Backup GuideWindows 10 makes data backups effortless. We have summarized every native backup, restore, recovery, and repair option we could find on Windows 10. Use our simple tips and never despair over lost data again!READ MORE

File History

File History lets you make regular, scheduled copies of any personal data on your PC. The app will save the backups on an external drive.7 Things to Know When Buying a Data Drive for Backups 7 Things to Know When Buying a Data Drive for BackupsThinking about buying a data drive for storing file backups? Here's what you need to know if you want to make an informed decision.READ MORE
To set up the app, go to Start > Settings > Update and Security > Backup and choose which drive you want to use.
windows 10 native backup
Windows will take care of the rest. By default, it will back up everything in your user folder every hour. To change which folders you want to back up and the frequency of the process, click More Options > See Advanced Settings.

System Image Backup

Navigate to Control Panel > Backup and Restore (Windows 7) > Create a System Image. Windows will automatically scan you system for suitable drives.  Choose where you want to save the system image, and follow the onscreen instructions.
windows 10 system image

Restore Backups

To restore your personal files, go to Start Menu > Settings > Update and Security > Backup > More Options > Restore Files From a Current Backup.
All the backups you made using File History will be listed. You can use the arrow keys to cycle between versions. Click Restore to save the file back in its original location or right-click and select Restore To to save it in a different location.
To restore system images, head to Start > Settings > Update and Recovery > Recovery > Advanced Startup > Restart Now. When the system has rebooted, go to Troubleshoot > Advanced Options > System Image Recovery.

Third-Party Options

The Windows tools perform admirably, but using one of the leading third-party tools will give you more options and more flexibility.

1. AOMEI Backupper Standard

Key Strength: Great for beginners.
AOMEI Backupper Standard is arguably the best tool for beginners thanks to its powerful wizard.
The app can create system images, perform both differential and incremental file backups, and back-up external hard drives, USB flash drives, network drives, and any other form of storage Windows can recognize. It can also back up a specific disk partition on your machine, rather than the entire hard-drive.7 Reasons to Use a NAS for Data Storage & Backups 7 Reasons to Use a NAS for Data Storage & BackupsExternal hard drives are great for data storage, but there are many more benefits to using a network-attached drive instead. Here's everything you need to know.READ MORE
aomei backupper standard
You can only save your backups to an external drive, there is no option to save to your cloud storage. NTFS, FAT32, FAT16, EXT2, and EXT3 file systems are supported.
Its best feature is its ability to back-up in real-time based on actions such as user logon, user logoff, system start-up and system shutdown.

2. Personal Backup

Key strength: Lightweight app.
Personal Backup is the smallest app on the list, weighing in at just 15 MB. It can only create standard data backups; it doesn’t offer system imaging.
You can save your data to any destination folder, including another file on your hard-drive. It offers a way to compress all your data into a ZIP file if space is an issue and you can encrypt all your data with an AES algorithm to boost your security.
personal backup app
The app can schedule your backups automatically. It performs them incrementally by default.

3. EaseUS Todo Backup Free

Key strength: The best all-round tool available.
EaseUS Todo Backup Free boasts more than six million home users, and with good reason.
You can use it to back up data, operating systems, hard disks, specific disk partitions, and individual files. It can run full backups, incremental backups, and differential backups. When restoring, you can select whether you want to recover individual files, certain folders, or entire disk volumes.
easeus todo backup free
The free version will let you make disk clones so you can migrate your operating system between SSD and HDD drives. The $24 premium offering includes event-based back-ups, Outlook backups, and FTP offsite copies.5 Things You Need to Consider Before Buying a Hard Drive 5 Things You Need to Consider Before Buying a Hard DriveBuying a hard drive? It's not that difficult if you know a few basic tips. We've assembled the most important features of a modern storage drive and what you should buy.READ MORE
Additional useful features include Android backups, password-protected backups, disk wiping, archive splitting, backup prioritizing, and limited write speeds to reduce the impact on system performance.

4. Cobian Backup

Key strength: Highly customizable.
With differential and incremental backups, ZIP compression, AES 256-bit encryption, multiple filters, a scheduler, and FTP backups, Cobian Backup is already a strong offering.How Does Encryption Work, and Is It Really Safe? How Does Encryption Work, and Is It Really Safe?READ MORE
Where it really excels, however, is in its impressive level of customization options. There are more than 100 settings you can play with, all of which help ensure you can create your backups exactly the way you want them.
cobian backup
The app also gives you a way to split backups into smaller chunks. It’s useful if your destination media have small amounts of storage.
Its biggest drawback is a lack of a restore option: you have to manually browse the backup folder and retrieve the files.

5. Clonezilla

Key strength: Open-source bootable environment.
Clonezilla isn’t an installable program, it’s a bootable environment that you launched from a CD or USB drive.
It’s highly powerful but doesn’t emphasize ease-of-use. Unlike competitors such as Redo Backup and Recovery, its main focus is on providing advanced options. You should give it a wide berth if you’re not experienced. If you are an expert, it’s possibly the best tool on the list.
clonezilla
It comes in two formats: Clonezilla Live and Clonezilla SE. Clonezilla Live is designed for single machine backups/restores, while Clonezilla SE can handle up to 40 machines at once.
The software supports almost every file system you can think of and can create image files on your local disk, a SSH server, Samba server, NFS server, and WebDAV server. AES-256 encryption is available.

Your Favorite Backup Software?

I’ve given you five recommendations and introduced you to the native Windows tools. The apps have different strengths and are designed to cover different user needs.
But there are lots more free backup apps available. If none of the ones I covered appeal to you, check out FBackupMacrium Reflect FreeComodo BackUp, or Genie9 Free Timeline instead.
Which is your favorite free backup software? What makes it so special? I’d love to know your recommendations. You can leave your tips in the comments below.
Image Credits: A3D/Shutterstock

5 Hidden Tips and Tricks for Google Chrome On Android

G oogle Chrome comes as a default browser installed on most Android phones. It is fast, responsive and comes with all the basic features...