The Emacs Way of understanding Humans and Computers

November 30, 2014 at 10:28 pm | Posted in Patterns | 1 Comment
Tags: , , , ,

I was using gNewSense frow sometime now and one thing about softwares endorsed or created by FSF is that you get to know some amazing ideas or some incredible ways of solving some problems that you never came across before and you yourself never knew those either. For example, take icecat, it comes default with libreJS add-on installed. Generally we think an OS can control your machine and then you. After using libreJS I see how you can use javascript in a web-browser to control the user, without giving any hint at all. User will use his computer for 10 years and for those 10 years he will not have slightest of the idea that he is being controlled. Then I came across duckduckgo search engine and then ThinkPenguin router  with 100% Freedom and then h-node  and now gNewSense.

When I used Emacs first time, in year 2006, after few weeks of usage I came across The GNU Project (open Emacs and press “Control-h g”), that one keystroke (C-h g) changed my life. I got hooked onto Linux forever (or GNU/Linux as RMS calls it). Since last few years, I have never used/installed any proprietary OS on my machine, my machine runs only on Linux, yes, no other OS, only and only Linux (something that majority of Software Engineering students and prfossionals in INDIA are always scared to do). Just few months back I came across gNewSense and from there I came across one gNewSense BlogPost, an introductory book on programming in Emacs Lisp written by Robert J. Chassell. For those who don’t know, Emacs is one of the most (if not the most) advanced text editors available. I am sure if you make a list of top 20 softwares ever created with best design ideas then Emacs will be one of them (and Apache web server will be there too along with several softwares starting with letter “g” 😉 ). Emacs is written using Emacs Lisp (a dialect of Lisp, an amazing language) while some parts are written in C for portability/efficiency reasons. I am using Emacs all the time for writitg code but I do admit I hardly make effective use of it. I think I use may be 10% of its power. I always wanted to learn more and the book written by Robert seemed like a decent start. I am already writing code from few years now and Robert mentioned that it is “not for experienced programmers” but I am reading it anyway because I always wated to understand Emacs and then this book is so interesing and engaging and I can not seem to put it down. It is as much interesting as The Man Who Sold The Moon . Whenever I will come across some idea that I will like then I will post about it here. So, here is the first design idea I really loved (I assume you are familiar with some dialect of Lisp. If not, then just read 17 pages of first chapter of Robert’s book. That will be more than enough. Do not worry, it will not take much time to read those)

  • You want to evaluate something written in Emacs Lisp ? Just open emacs, put cursor at the end of the variable or function name or the closing parenthesis or whatever you want to evaluate and press “C-x C-e” and you got the answer. That’s it, that is how simple it is in Emacs.
  • File and Buffer are two different entities. File is what permamently stored on your computer’s hard disk whereas a buffer is inside emacs which will go away as soon as you exit emacs. A buffer visits the file or is a pointer to the file, not the actual file. You want to save changes into the file then just save the buffer and changes will be written to the file.
  • This one is most interesting. switch-to-buffer is an Emacs Lisp function that helps you in switching to another buffer. Generally when you look at any editor (Notepad, Notepad++ or gedit etc. for example) , you usually look at the file you are editing. If you switch to another file then you will see only and only this another file and previous file will not be visible. Previous file is open but it is not visible and hidden in the editor). What I mean is you can see only one file in front of you, not two (I am not talking about splitting-frames). Within Emacs code, switch-to-buffer is less used than set-buffer. Why ? … Because computer does not need eyes to see while humans do. When a a computer program needs to work on a buffer/file, it does not need to see it, visibility is not needed. switch-to-buffer was designed for humans and it does two things:
    • It switches to the new buffer .
    • It switches the buffer “displayed” in the window with new one.

You can easily guess now that set-buffer only walks the first step, it switches the program to other buffer while buffer on the screen remains unchanged.  Doesn’t this concept feel like one of the rules of the creation of this Universe while still being so simple and straightforward. I salute RMS for creating Emacs and keeping it free


Copyright © 2014 Arnuld Uttre, Hyderabad, Telangana – 500017 (INDIA)

Licensed Under Creative Commons Attribution-NoDerivs 3.0 license (a.k.a. CC BY-ND)

Advertisements

Linked List implementation of a Queue in C

May 13, 2009 at 11:51 am | Posted in C++ | 7 Comments
Tags: , , , , , , , , ,

A Queue is a FIFO based data structure. I tried to create one and got lots of advices and improvements from comp.lang.c folks. I am posting it here, in case someone gets benefit from that. I believe in Open Sharing of source code, it helps the community, it helpes the poor people like me who either did not have money to join some course or did not have enough of experience or a Master’s degree to get a job. Working on an Open Source software greatly improves the ability of the people to write quality code and also (as a side-effect) consumer always gets a robust product, a piece of software that they can trust. I am defnitely sure, you can’t trust a proprietary software, no one knows what its doing on your computer (except of the compnay who created it). MNCs are only intersted in making money and taking control of the market and doing a dishonest business always makes more money than doing an honest business. Having secrets of other corporations delievered to your doorstep always helpes in building a monopoly and I think proprietary software is a brilliant concept to spy on other companies and homes of general public. Never ever forget the Russian gas piple-line scandal. Perhaps reading some news will help.. You can even check amazon. Whether you are a government or an organization or an individual, you can not trust a piece of proprietary software, you don’t know what it does, you will never know.

I have seen people writing poor quality C code for years. They wrote poor C programs when they were 23 ( starting their Master’s degree) and when they were 25 (first day of the job) and now they are 29 and after 4 years of experience they still write poor quality code (Mostly these people are also the ones who have passed their professional degree in first division). Its because they are working in proprietary software based business company because of which they can not share their code. No critics and hence no improvement and in their spare time they never tried to read comp.lang.c archives though they do get time to shake beer glasses with their friends sometime or joke about the habist of their fellow team-mates or their boss or whetever they like but they never get time to read comp.lang.c

. You can always find the original duscussion of my program on Usenet.

/* This Queue implementation of singly linked list in C implements 3 
 * operations: add, remove and print elements in the list.  Well, actually, 
 * it implements 4 operations, lats one is list_free() but free() should not 
 * be considered the operation but  a mandatory practice like brushing 
 * teeth every morning, otherwise you will end up loosing some part of 
 * your body(the software) Its is the modified version of my singly linked 
 * list suggested by Ben from comp.lang.c . I was using one struct to do 
 * all the operations but Ben added a 2nd struct to make things easier and 
 * efficient.
 *
 * I was always using the strategy of searching through the list to find the
 *  end and then addd the value there. That way list_add() was O(n). Now I 
 * am keeping track of tail and always use  tail to add to the linked list, so 
 * the addition is always O(1), only at the cost of one assignment.
 *
 *
 * VERISON 0.5
 *
 */

#include  <stdio.h>
#include  <stdlib.h>
#include  <string.h>


struct my_struct
{
  int num;
  struct my_struct* next;
};


struct my_list
{
  struct my_struct* head;
  struct my_struct* tail;
};


struct my_list* list_add_element( struct my_list*, const int);
struct my_list* list_remove_element( struct my_list*);


struct my_list* list_new(void);
struct my_list* list_free( struct my_list* );

void list_print( const struct my_list* );
void list_print_element(const struct my_struct* );


int main(void)
{
  struct my_list*  mt = NULL;

  mt = list_new();
  list_add_element(mt, 1);
  list_add_element(mt, 2);
  list_add_element(mt, 3);
  list_add_element(mt, 4); 
  
  list_print(mt);

  list_remove_element(mt);
  list_print(mt);

  list_free(mt);   /* always remember to free() the malloc()ed memory */
  free(mt);        /* free() if list is kept separate from free()ing the structure, I think its a good design */
  mt = NULL;      /* after free() always set that pointer to NULL, C will run havon on you if you try to use a dangling pointer */

  list_print(mt);

  return 0;
}



/* Will always return the pointer to my_list */
struct my_list* list_add_element(struct my_list* s, const int i)
{
  struct my_struct* p = malloc( 1 * sizeof(*p) );

  if( NULL == p )
    {
      fprintf(stderr, "IN %s, %s: malloc() failed\n", __FILE__, "list_add");
      return s; 
    }

  p->num = i;
  p->next = NULL;


  if( NULL == s )
    {
      printf("Queue not initialized\n");
      free(p);
      return s;
    }
  else if( NULL == s->head && NULL == s->tail )
    {
      /* printf("Empty list, adding p->num: %d\n\n", p->num);  */
      s->head = s->tail = p;
      return s;
    }
  else if( NULL == s->head || NULL == s->tail )
    {
      fprintf(stderr, "There is something seriously wrong with your assignment of head/tail to the list\n");
      free(p);
      return NULL;
    }
  else
    {
      /* printf("List not empty, adding element to tail\n"); */
      s->tail->next = p;
      s->tail = p;
    }

  return s;
}


/* This is a queue and it is FIFO, so we will always remove the first element */
struct my_list* list_remove_element( struct my_list* s )
{
  struct my_struct* h = NULL;
  struct my_struct* p = NULL;

  if( NULL == s )
    {
      printf("List is empty\n");
      return s;
    }
  else if( NULL == s->head && NULL == s->tail )
    {
      printf("Well, List is empty\n");
      return s;
    }
  else if( NULL == s->head || NULL == s->tail )
    {
      printf("There is something seriously wrong with your list\n");
      printf("One of the head/tail is empty while other is not \n");
      return s;
    }

  h = s->head;
  p = h->next;
  free(h);
  s->head = p;
  if( NULL == s->head )  s->tail = s->head;   /* The element tail was pointing to is free(), so we need an update */

  return s;
}
  

/* ---------------------- small helper fucntions ---------------------------------- */
struct my_list* list_free( struct my_list* s )
{
  while( s->head )
    {
      list_remove_element(s);
    }

  return s;
}

struct my_list* list_new(void)
{
  struct my_list* p = malloc( 1 * sizeof(*p));

  if( NULL == p )
    {
      fprintf(stderr, "LINE: %d, malloc() failed\n", __LINE__);
    }

  p->head = p->tail = NULL;
  
  return p;
}


void list_print( const struct my_list* ps )
{
  struct my_struct* p = NULL;

  if( ps )
    {
      for( p = ps->head; p; p = p->next )
	{
	  list_print_element(p);
	}
    }

  printf("------------------\n");
}


void list_print_element(const struct my_struct* p )
{
  if( p ) 
    {
      printf("Num = %d\n", p->num);
    }
  else
    {
      printf("Can not print NULL struct \n");
    }
}

 

 


Copyright © 2006, 2007, 2008 Arnuld Uttre, #331/type-2/sector-1, Naya Nangal, Distt. – Ropar, Punjab (INDIA) – 140126

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.

The Old-Fashioned Business

September 16, 2008 at 4:47 pm | Posted in History, Patterns | Leave a comment
Tags: , , , ,

A long time ago I heard that viacom was going to sue Google (YouTube) for copyright violations. Recently I read about it on web. I also read recently that Symantec has sued Microsoft over Vista. See here, here and here. Then a little googling told me its actually an international business idea. IBM sues PSI, Alcatel sues Microsoft, Google sues Microsoft, Microsoft sues Google. Then I thought of Halloween Documents where Microsoft said that to completely obliterate Open Source Software, they need to target Open Source Phenomenon rather than one or two companies. At least they have the talent to understand that.

Now that really does not make any sense. All companies like Microsoft, IBM, D-Link, Apple, HP and many other biggest Software players in the market all make money using Proprietary formats, they all are in the same business, they all use same weapon to make money, code-secrecy a.k.a software-patents and then they also sue each other over patent infringements. It really does not make much sense but If you look closely over the incidents you will see a pattern emerging out of your browser, telling you something. In World War 2, in the totalitarian government of Hitler, the power means secrecy. How the Enigma cipher worked. How Allies cracked this highly cryptographic machine. Hitler’s war tactics were completely sabotaged when Enigma code was cracked. A totalitarian government has one weapon and it uses it in parliament, in intelligence, in police, in administration, in business, in itself.. this weapon is called secrecy and when it gets broken, its very easy to take them down. This is what happened in Germany in World War 2 and this is what is happening in US right now. Unfortunately the software is working the way, the companies who have monopoly over some products (monopoly on software patent exactly works in totalitarian way) like Apple over iPod, Microsoft over Desktop, Google over web are using code-secrecy as their primary weapon. They all share one common thing, software-patent, dictatorship over the people who use their products on they gonna use them, exactly like how you gonna live if you are a Jew and its 1933 and you are currently in Germany. All of these proprietary software companies have only one weapon, that makes them stand under one umbrella, under one common cause: Code-Secrecy. Even after this they all fight with each other, spend billions of dollars in courts and in settlements out of courts every year. What does that mean ?

That means the owners and runners (and the managers who help those runners) of multi-billion corporate companies have vulnerabilities in their character which can be exploited very well by companies running business without secrecy, making money on Open Source software. I also very firmly believe that those weaknesses of characters can be written down in the form of a Reference Manual which every Open Source business company should read before they start to create their business strategy. Again, the question is not of the cry of a single giant like Microsoft, it is of a process called proprietary software which has gotten hit with Open Source[1]. If these companies want to not only stand but grow in the this highly competitive market then they need to come to one with each other. They need to aid and nurture and help each other otherwise Open Source will keep on hitting all of them every hour, every day, every month every year. Better, they adapt to new ways of doing software business, after all , to grow a business means to change and adapt and take the dollar in return of it 🙂 .

Open Source has put light on the fact that code-secrecy is the old-fashioned way, that market has changed now. The ones who will stand on the new and changed concepts of business are the ones who will be the forerunners of the future. No company, with enough self-respect, wants to be in the business for short-term. Every company desires to have the monopoly over the market. Those who understand the business and foresee the future become the ones nearly impossible to defeat. Take Google, their founders tried to sell their search engine and no one liked the idea. After 10 years, see where the Google is, Google has made so much money in 10 years that took Microsoft 25 years to collect. Business paradigms are getting shifted, ways of doing software business change as fast as a software decade passes. You decide where you want to stand, wither you are the one or not. There is no place for medium-profit lurkers in todays Software world. Either you are in or you are out. You decide. Before you refute my article make sure you read how Red Hat has started into Open Source business. How their founders learned that making money on proprietary software and making money on Open Source software are not very much different when it comes to business. The thing, which they never said, I think is, in Open Source, there is No Fear of losing the code, you have already learn how to manufacture dollars by sharing of code. Sharing of Code is the biggest nightmare of every proprietary software company and this is the tool that their competitors can exploit to maximum extent. This fear is open and free and code-secrecy is the Enigma that can be cracked by some penniless but an individual with a sense for business. you only need courage and logic of business in doing so. Good Luck 🙂

[1] Its not like that companies whose business is based on code-secrecy will go out of business. They will remain here for a much longer time. My point is over a decade from now, they will no longer be the kings, though they will be cutting millions every year.

 

 

Copyright © 2008, Arnuld Uttre, #331/type-2/sector-1, Naya Nangal, Distt. – Ropar, Punjab (INDIA) – 140126

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.

Open Source, Salary & Society

September 12, 2008 at 5:53 pm | Posted in Patterns, Programming | 2 Comments
Tags: , , , , , , ,

Very Recently I read an article titled Franchise by Russ Nelson. I was quite impressed by the man’s talents. He says that even if we have Free Software running on all across the world, the salaries of programmers will still be on a higher scale and he concludes by disagreeing with the Richard Stallman. I was very happy th at he disagrees on such a point on technical basis rather than biased opinions. On the basis of my very small amount of experience in software and my experience in analyzing the general life, business aspects and experience by the habit penetrating deep into the economics I can very strongly state an opinion which is very different both from Russ Nelson and Richard Stallman. When Russ Nelson said In a free market, over time, competition in the production of a commodity product will eliminate all profits, he was right and he was talking about the business owners, the lords of the companies. He is not talking about programmers. At such point, after such threshold, the salaries of programmers will become independent no matter whether the programmer will be working in company creating proprietary softwares or in a company creating free softwares.

One more thing I am sure of that will happen is the reduction in the number of poor programmers getting high-paying jobs and that will relieve Joel Spolsky of his worries a bit about poor quality software 😉 . Since at that point humanity will be liberated from poor thoughts, businessmen will come to one in contact with quality programmers and in conflict with poor ones. Either you make quality bread or you shut down your bread house, which a business man will not. He will simply fire the poor bread maker and hire a good one who can practically make good breads, not theoretically. Myself, personally, I really hate it when I see good, quality programmers earning 20% of the salaries than poor ones who with years of experience still use void main() and solve problems using arrays all the time in C++.

Now the only question remains is salary will be on a higher side or on lower plane. I am sure both salaries of programmers and software coming out of the hands of programmers in such an open market, will get better. I don’t think programmers will get way much higher. I repeat both softwares coming out of the hands of the programmers and salaries of those programmers will be better than what we are getting in today’s proprietary, closed and non-cooperative corporate culture. I think good programmers in such an era will not be poor like what we have the situation now.

That trend has to go, good programmers need to be paid good and poor programmers need to be fired. In fact poor programmers must be capsuled in a spaceship and need to be sent away to the Saturn at minimum, so that they will no loner be able to pollute and handicap our society’s intellectual humans and our kids. This time is still years ahead, it may take a decade before it happens but who knows, after all software is field which is totally different and unusual of all the professions exist today. I am glad to be a Computer Programmer.

 

 

Copyright © 2008, Arnuld Uttre, #331/type-2/sector-1, Naya Nangal, Distt. – Ropar, Punjab (INDIA) – 140126

Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice, and the copyright notice, are preserved.

Blog at WordPress.com.
Entries and comments feeds.