Julia, The Language I was waiting for

March 6, 2018 at 6:46 pm | Posted in Data Science, History, Julia | Leave a comment

I have programmed in C for 5 years now. I can say from experience, after first 1.5 years, I began to understand pointers, malloc and arrays of pointers to pointers of structs containing pointers. I really mean begin. In K&R2, authors said that they feel after 10 years in C, they are still learning. I used to struggle to think in C for 3-4 years. 5th years totally changed that. I can solve problems in C after 5 years of experience which I never could never did earlier. Like this Google Interview Question. I am very much confident in C now. Imagine 10+10 more years in C, what it will make me, a Samson of C ? I have, personally, coded in many languages, e.g.:

  • Common Lisp
  • Scheme
  • OCaml
  • Haskell
  • Ruby
  • ATS
  • At least 20 others I forgot.

I could never use them professionally on large scale. Just some toy programs here and there and sometimes bit bigger those of Practical Common Lisp, The Gigamonkeys Book. I loved Common Lisp but could never use it. When every good company started having Python in their job description, I was still loving Common Lisp and thinking that is from where Python got most of ideas. Then last month I came across Julia. It looked like Rubty to me (in syntax) but it was faster, way faster than any language, it is just bit slower than C,C++. It joined Petaflop club recently. Working with so many languages taught me 2 things: along with the tech and features, a Programming Language is lot about its design and whys. It has a mental model behind. I was looking for a language with speed of C, with an Open-Source License and where I could have dynamic typing too. A language where I could use my mind to solve a problem than memory problems and Segfaults. A language which is far simpler than C++ (By all means, C++ is a great language, if I have to create an OS, I would use it. Still, it is a very complex language to work in it). Then I came to realize, I was not the only one thinking along those lines. Few Lispers were thinking same. Then I read Why of Julia. I felt like it was written for me. Out of all those experiences and experiments over half a decade, I can tell you, Julia is really a great language to code in at least for 5 years of your life. I am sure, any person who likes to improve his skills, looking for better ideas, better design in software, will love Julia. I am typing this from my home computer running Arch Linux with LXQt. It is amazing to chat on Julia IRC gitter at 10:15 PM in night

Julia community is quite friendly and helpful. One thing i can’t take off my mind is when I was writing toy programs in Python and Ruby. Python looked much friendlier and Ruby looked alien (think less intuitive) and C hurt the head. I read Why’s Poignant guide to Ruby at that time. After 5 years coding totally in C and C++, I feel quite comfortable with both, they still surprise me though sometimes. I don’t know but whenever I look at Julia code/syntax, it always reminds me of Ruby code/syntax . The syntax feels same, less intuitive. I struggle a bit too. Writing Python code I felt was much easier but that easiness and friendliness and intuitiveness wore-off in a week. At the same time of trying out a 100 different languages and environments, I think this easiness/friendliness or lack of it has not much to do with mastering the language and its design and liking it at heart. It all comes with practice and associating with people who already know the language, you just have to follow their guidance. So, yeah, Julia community is full of helpful people. I am still wondering though how long it will take me to get over this mental obstacle of lack of intuitiveness towards Julia syntax. I only know one way, get totally immersed in the language and community and write good code, read reference docs/manuals, read blogs & articles on Julia.

I like Lisp a lot, you will too if you work with it. Lisp could never break out into the mainstream. The languages it influenced (Python, Ruby, Scala, Perl etc., even Julia) all became mainstream but Lisp could not. I have even read Kent M Pitman‘s really long conversations on Scheme Language Standard on comp.lang.scheme newsgroup (try Aioe and Pan Newsreader ) when I was choosing to learn between Scheme and Common Lisp (one such conversation can be found on Google Groups) . I read all that out of strong interests, now I realize it was all a part of experience towards greater understanding of programming languages. I liked Lisp and I wanted performance. I think Julia will be mainstream in few years and it is the language I was waiting for since the day I wrote my first program. If you like coding/programming even a bit, if it touches your heart even a little bit. You must code in Julia, must read its documentation. It is a breath of fresh air after a long time.


Copyright © 2018 Arnuld Uttre, Hyderabd, Telangana – 500017 (INDIA)

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Advertisements

Google Interview Round 2 Question

February 9, 2018 at 4:11 pm | Posted in C++, Hacking, Programming | 1 Comment

I was just searching for C and C++ related topics and came across Google interview question.:

/**
*
* Google OnSite Round 2
*
* Input is an integer array A
* Return an array B such that B[i] = product of all elements of A except A[i]
*
*/

Original Question was on CareerCup. I wrote an algorithm on paper in 7 min and took me another 10 min to type it in computer. Do it without using division.

Continue Reading Google Interview Round 2 Question…

Literate Programming

January 10, 2018 at 10:43 am | Posted in Hacking, Programming | Leave a comment
Tags: , , , , ,

I was reading Knuth’s The Art of Computer Programming, the seminal in algorithms. I was unable to understand some parts of section 1.2.10 (analysis of an algorithm), so I asked on IRC channels (like ##programming, ##c, #haskell etc.) and I came across More Shell, Less Egg. Go read that article and come back here.

I hope you have finished reading that article. A few years back I came to know about Literate Programming. I was curious about it, I read some articles on it and really loved the concept. Fast forward to 2018, I am a full-time computer programmer with several years of experience now and my thinking has changed. So how does literate programming look now ?

I read full article and was quite impressed by the cleverness and experience of both Mcllroy and Knuth. Now Mcllroy is a UNIX guy (he wrote UNIX pipes). UNIX gurus are very practical and wise when it comes to solving problems. But I found myself little bit wrong in comparing a shell script with a full fledged programming language available on a variety of systems. Then I came across this comment by Charles Wolfe:

most comments tend to become useless rather rapidly and having the documents wholly separated from the code make the cross referencing or consultation of docs to understand code difficult most of the time.

I have to agree with that as per my own experience (it may not be valid all the time and this is how most of the industrial code is written). We combine that with another very practical blog post by Franklin Chen. He used 2 pieces of codes to prove his point, first one, normal Haskell code and 2nd, Haskell code written with documentation (something like Haskell’s own WEB system). If you look carefully you can see that one with documentation is not much readable (at least I felt horrible when I tried to read it).

So, What Do I think now in 2018 after working in software industry ?

Let me make it very clear that Knuth is a brilliant guy, I respect him a lot. I even someday want to learn from him by sitting next to him teaching me 🙂 . We are talking here about Software Industry, the commercial interests. I think Literate Programming will not spread into the software industry. First of all, industrial software developers (at least here in India) do not care much about comments. I do write hell lot of comments but that is because I was learned my skills on USENET whereas most industrial programmers in India learned from usual engineering colleges where commenting your code well, is not part of the picture. There is no paradigm of “you will write it once and it will be read 10000 times, so help your fellow programmers by telling them what are you doing” (I just industrialized the quote from Knuth: “Programs are meant to be read by humans and only incidentally for computers to execute.”).  2nd, there is lot of job-shifting happens in industry. By the time  a project comes to its completion, there is a possibility that  1000 different people have worked  on it who never communicated with each other, hence,  lot of code changes and many times, comments, sooner or later, become irrelevant. Some comments stay same, many don’t. 3rd, managers in industry want solutions fast and even though, most of the time, such attitude hurts the software and hence the company in long term but then I do not think it is their fault because they have pressure on them to deliver. So, if a project takes a month to design, code and test and deliver then you have to get it done by next week. In such cases, all things not related to “fast delivery” are generally ruled out. If it is not a whole project and there is problem you have to solve then  because of “fast delivery” requirements, UNIX tools win. I have experienced both. You can’t beat UNIX tools there with a general purpose language.  So, I think Literate Programming  will never catch up in industry.

Copyright © 2017 Arnuld Uttre, Hyderabd, Telangana – 500017 (INDIA)
Licensed Under Attribution-NoDerivs 3.0 United States (CC BY-ND 3.0 US)

C quiz

January 4, 2018 at 3:30 pm | Posted in Programming | Leave a comment

I was looking at an online C language quiz and came across this:

#include <stdio.h>

int main(void) {
 struct myStruct
  {
    int num = 10;
  }var;

  printf("%d\n", var.num
);

  return 0;
}

This will never compile. Guess why. Because You can’t initialize struct members in declaration. Here is what gcc 7.2.1 will throw:

[arnuld@arch64 programs]$ gcc -ansi -pedantic -Wall -Wextra t.c
t.c: In function ‘main’:
t.c:6:13: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
int num = 10;
^
t.c:4:9: warning: struct has no members [-Wpedantic]
struct myStruct
^~~~~~~~
t.c:9:21: error: ‘struct myStruct’ has no member named ‘num’
printf(“%d\n”, var.num
^
t.c:7:4: warning: variable ‘var’ set but not used [-Wunused-but-set-variable]
}var;
^~~
[arnuld@arch64 programs]$

You can do this instead:

#include <stdio.h>

int main(void) {
 struct myStruct
  {
    int num;
  }var;

  var.num = 10;
  printf("%d\n", var.num);

  return 0;
}

Then you get this:

[arnuld@arch64 programs]$ gcc -ansi -pedantic -Wall -Wextra t.c
[arnuld@arch64 programs]$ ./a.out
10
[arnuld@arch64 programs]$

But this will not work:

#include <stdio.h>

struct myStruct
{
  int num;
}var;

int main(void)
{
  var x;
  x.num = -1;
  printf("%d\n", x.num);

  return 0;
}

[arnuld@arch64 programs]$ gcc -ansi -pedantic -Wall -Wextra struct.c
struct.c: In function ‘main’:
struct.c:11:3: warning: statement with no effect [-Wunused-value]
var x;
^~~
struct.c:11:7: error: expected ‘;’ before ‘x’
var x;
^
struct.c:12:3: error: ‘x’ undeclared (first use in this function)
x.num = -1;
^
struct.c:12:3: note: each undeclared identifier is reported only once for each function it appears in
[arnuld@arch64 programs]$

Can you guess why ?

Because /var/ is a myStruct variable, not a type. If you want it to be accessible inside main() then you have to make it a type using typedef, like this:

#include <stdio.h>

typedef struct myStruct
{
  int num;
}var;

int main(void)
{
  var x;
  x.num = -1;
  printf("%d\n", x.num);

  return 0;
}

[arnuld@arch64 programs]$ gcc -ansi -pedantic -Wall -Wextra struct.c
[arnuld@arch64 programs]$ ./a.out
-1
[arnuld@arch64 programs]$

C is a very small language. You can put entire C language in your head if you do few years of serious coding in C. For the standard libraries, you have have H&S5.

Copyright © 2018 Arnuld Uttre, Hyderabd, Telangana – 500017 (INDIA)
Licensed Under Attribution-NoDerivs 3.0 United States (CC BY-ND 3.0 US)

Interview Question — Printing a Palindrome

May 9, 2017 at 4:35 pm | Posted in Programming | Leave a comment

This was asked recently to me in an interview. Problem is explained in the comments:

/* GlobalEdx interview Question, Real Life Practicial Code
*
* If a user enters D then write a program to print like this:
*  A B C D C B A
* If user Enters J or Z then it should print till J or Z
* like above. Program should work for every letter of English
*
*/

#include <stdio.h>

void printPalindrome(char c) ;
int getFirstLetter(char* p, char* pc);

int main(int argc, char* argv[]){
char c;
if(2 != argc) {
printf("Please provide 1 argument\n");
}
else
{
if(!getFirstLetter(argv[1], &c)) printPalindrome(c);
else printf("You did not enter a character. Enter uppercase character \n");
}
return 0;
}

/* If you get more than letter. Just pick up the first letter
*
*/
int getFirstLetter(char* p, char* pc) {
char temp = *p;

/* What if user puts an int or double, here we handle that ? */
if( ((temp >= 'A') && (temp <= 'Z')) ) {
*pc = temp;
return 0;
}
else return 1;
}

void printPalindrome(char c) {
char t;

for(t='A'; t != c; ++t) printf("%c, ", t);
for(; 'A' != t; --t)     printf("%c, ", t);
printf("%c\n", t);
}

OUTPUT:
[arnuld@arch64 programs]$ gcc -ansi -pedantic -Wall -Wextra palindrome.c
[arnuld@arch64 programs]$

[arnuld@arch64 programs]$ ./a.out BA
A, B, A
[arnuld@arch64 programs]$ ./a.out D
A, B, C, D, C, B, A

[arnuld@arch64 programs]$ ./a.out 0
You did not enter a character. Enter uppercase character

[arnuld@arch64 programs]$ ./a.out 0*
You did not enter a character. Enter uppercase character

[arnuld@arch64 programs]$ ./a.out {
You did not enter a character. Enter uppercase character
[arnuld@arch64 programs]$

Copyright © 2017 Arnuld Uttre, Hyderabd, Telangana – 500017 (INDIA)
Licensed Under Attribution-NoDerivs 3.0 United States (CC BY-ND 3.0 US)

Next Page »

Create a free website or blog at WordPress.com.
Entries and comments feeds.