My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label difference. Show all posts
Showing posts with label difference. Show all posts

Friday, July 10, 2020

Line ending difference - Windows vs Linux Mac : Line Breaks \n CRLF explained and resolutions in Python, Java, Javascript, C++, Node.JS etc


The Windows environment and the UNIX environment use different end of line characters.  So, if you are sharing files between the environments, one of the environments sees end of line characters at the end of each line of text that it does not normally expect, while the other may give error.

In general, z/OS UNIX text files contain a newline character at the end of each line. In ASCII, newline is X'0A'. In EBCDIC, newline is X'15'. (For example, ASCII code page ISO8859-1 and EBCDIC code page IBM-1047 translate back and forth between these characters.) Windows programs normally use a carriage return followed by a line feed character at the end of each line of a text file. In ASCII, carriage return/line feed is X'0D'/X'0A'. In EBCDIC, carriage return/line feed is X'0D'/X'15'.



As per my research, when you give a Line break there are different behaviours or interpretation based on the platform you are using:


  • Windows: '\r\n'
  • Mac (OS 9-): '\r'
  • Mac (OS 10+): '\n'
  • Unix/Linux: '\n'


Resolution:

Identify in the program which operating system you are using. From there find the Line separator value. Following are the methods you can use for some different programming languages you would use:


Python:

import os
os.linesep

Java:

System.lineSeparator()

NodeJS:

require('os').EOL

C++:

Many methods including Boost Library
One method QDir::separator().toAscii()

C#

string eol = Environment.NewLine;


Cheers :)

Friday, November 17, 2017

Difference between Nuget and Chocolatey

NuGet is designed to allow you to easily add code libraries to your project. Things like JSON.NET, Entity Framework, etc.


Chocolatey is actually built on top of the NuGet package system, but it is designed to fill a different need. Chocolatey wraps up applications and other executables and makes it easy to install them on your computer. For example, tools like Git and Notepad++, etc. can be easily installed with a command like: cinst git.


To know more about chocolate and how to install it please refer my earlier blog post on W3LC : http://www.w3lc.com/2017/11/what-is-chocolatey-and-how-to-install.html


https://chocolatey.org/packages has a list of all the applications that can be installed.


If you have an open source project which is a library that is to be used in other developers' projects, then you should submit it to NuGet.


If it is an application that users would normally install, then create a Chocolatey package that users can easily install and update from the command line.


Details of different Package manager tools and where does Chocolate fits in:


OneGet has been renamed to Package management. It's core provides you with discovery and installation/uninstallation of various packages. OneGet is often referred to as a "package manager manager".

OneGet is a part of WMF 5 installation. Think of this as the "central concept" in the big picture. Now let's talk about packages.

Packages are fetched through package providers. E.g. PowerShellGet is one package provider for OneGet. Powershell gallery is a package source of of PowershellGet (PSGet). A provider can have multiple sources where it can search for it's packages.

E.g for the nuget-package provider; you can easily add the sources to the public nuget gallery and register your own e.g. myget source so it can be used when searching for packages.

Chocolatey is just another example of a package provider. Earlier it had to be installed and was a seperate module with it's own logic. The new Chocolatey provider conforms to the new framework of installing / managing packages.

So on a more conceptual level; a package provider itself contains information on how to install and search it's sources (sources can be registered/unregistered for each and every provider); whilst OneGet (Package management, package manager manager) works on the level above, managing package providers and interfacing this all for you.

OneGet glues it all together; while the providers itself knows how to handle packages based on it's registered sources.

Hope this explains it on the conceptual level.

See also this nice blogpost here explaining a few things more in detail:https://blogs.technet.microsoft.com/packagemanagement/2015/05/05/10-things-about-oneget-that-are-completely-different-than-you-think/

If you want to play around with package providers and sources :

 Get-PackageProvider # -Shows package providers installed on your machine)
 Find-PackageProvider # -Find online package providers you can pull down and install)
 Get-PackageSource # -List all package sources, with it's provider name)
 Register-PackageSource # -Register new package source for a provider)





Saturday, November 24, 2012

Python - Tuple Vs List - Difference/ Comparison


Tuples and Lists have always attracted the learners of Python. And, to the most of employers, the difference between them still maintains favoritism. Searching over the Internet gives you the distinction between them, but to many the language used all over seems to not help much. And worse part is that, not all the differences have ever been published at one place. And the worst of all, sometimes technical slangs have been used, with no direct meaning or examples to make it clear.

Let me start with a very brief introduction to what these Datatypes are about. Following description of List and Tuple is an excerpt from my "How To Tame Python" guidebook.

List is one of the most helpful and versatile data type available in Python. A list contains several items separated by commas. The items are enclosed within square brackets ([]). The list comes with built in functions which can be used to add, delete, edit contents in a list. Any subset of a list returned is also a list. Also note that like strings here also the Index starts from 0 and goes to the Length of the list minus 1.
A typical list can be as simple as :
list=[2,4,8,16,32], or
list2=['how','to','tame','python'], 
Or it can be a mix of datatypes for eg.
list3=[1,'january',2.23,-3]

Tuple again is a data type that is similar to the list. However, elements of a tuple are enclosed within parentheses. [Remember elements in a list were enclosed in square paranthesis]. It is important to mention that a Tuple is a read-only list. Any subset of a tuple returned is also a tuple. Also note that like strings, and list, here also the Index starts from 0 and goes to the Length of the tuple minus 1.
Eg. tup1=(12,'leo',23.45)


After completing my "How To Tame Python" guidebook, addressing this issue was the most immediate task. I am thankful to the memories of my sweetheart, while she was away, that kept me awake till night and motivate me in finding out the real differences. I actually programmed and validated each statement I said below. There are differences in Tuples and a List. I have discussed them in following classes of distinctions. So, here comes the difference between Tuples and List in Python.

Class A:  Usage difference due to Runtime difference 
Tuples are Immutable. 'tuple' object does not support item assignment
Because they are immutable, a Tuple can be used as a Key in a Dictionary.
There may be a slight performance improvement in Tuple.
For eg.
Allocation in a book can be a combination of a page number and line number, eg (x,y)
Similarly, your gps coordinates can be (x,y)
It is a tuple because these things are immutable. As soon as either x or y changes, the meaning itself changes.
And now, some short notes can be added to these locations using a dictionary.

Class B:  Difference in what they mean due to Semantic difference
Tuples are hetrogenous data structure, while lists are homogenous. There is a semantic difference too. Tuples have structure, while lists have order. Tuples (generally) are sequences of different kinds of stuff, and you deal with the tuple as a coherent unit. But, Lists (generally) are sequences of the same kind of stuff, and you deal with the items individually.
Eg 1.
Consider the following two data structures:
>>> time.localtime()
(2012, 3, 7, 11, 45, 38, 2, 33, 0)
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
The first one, a tuple, is a sequence in which position has semantic value. The first position is always a year. This tuple functions as a lightweight record or struct. The second one, a list, is a sequence where we may care about order, but where the individual values are functionally equivalent.
Eg. 2
Consider example of the simultaneous use of both types. If you look the Python Database API fetchmany() method, you will see that it returns the result of any query as a "List of Tuples". The result set as a whole is a list, because rows are functionally equivalent (homogeneous). There is only a order, and no importance which row is what. But the individual rows are tuples, because rows are coherent, record-like groupings of (heterogeneous) column data. We know that first element means what and second elements mean what, and so on.


Class 3:  Usage as Enum or Stuct because of namedtuple() method

This difference becomes more visible as soon as you read about namedtuple in Python
Named tuples assign meaning to each position in a tuple and allow for more readable, self-documenting code. They can be used wherever regular tuples are used, and they add the ability to access fields by name instead of position index. Named tuples are especially useful for assigning field names to result tuples.
Syntax:
collections.namedtuple(typename, field_names, verbose=False, rename=False)
It Returns a new tuple subclass named typename. The new subclass is used to create tuple-like objects that have fields accessible by attribute lookup as well as being indexable and iterable.
Eg.
EmployeeDetail = namedtuple('EmployeeDetail', 'id, name, age, job, department, paygrade,address')


I have realized these differences after years of coding and using Python. Many of the differences, were always in sub-conscious mind and never came out. It was only when I was completing my "How To Tame Python" guidebook, that the idea of documenting the differences came to my mind. And, after this has been done, I was more than glad to find out that this is the best article over this subject. I have been informed by my friends and readers across the globe that they have found this article very helpful in their projects, understanding the Python, and their Job interviews.

You can also send me your feedbacks on this blog, or to my personal email id: Toughjamy@Yahoo.com
--Mohd Anwar Jamal Faiz