Jason's Blog

L & Cod 

10 ways to improve your programming skills

 

1. Learn a new programming language

Learning new programming languages will expose you to new ways of thinking; especially if the new language uses a paradigm which you aren’t yet familiar with. Many of the ways of thinking that you will learn can be applied to languages that you already know, and you might even want to start using the new language for serious projects as well.

Good languages providing a great educational experience (but not necessarily limited to that) include any Lisp (Scheme is good), ForthPostScript or Factor (stack-oriented programming languages), J (wonderful array programming language), Haskell (strongly typed purely functional programming language), Prolog (logic programming) and Erlang (concurrent programminggoodness).

2. Read a good, challenging programming book

A lot can be learnt from books. While practice is important, reading one of the really good andchallenging programming books can be a great way to challenge your thinking and even move it up by a level. Such challenging books would include The Art of Computer Programming (if you want areal challenge), Structure and Interpretation of Computer Programs (SICP), A Discipline of Programming or the famous dragon book.

You can go with less challenging books as well, but avoid books that are “for Dummies” and will teach you something “in 24 hours” or “in 21 days”; you will get very little out of such books in terms of improving programming skills.

3. Join an open source project

What are the advantages of joining an open source project? You will work with others (good thing in case you have only worked on personal projects before), and you will have to dig into, and learn to understand, an unfamiliar code base (which can be challenging).

You can find different projects on sites such as GitHubSourceforgegitoriousBitBucket orOhloh.

4. Solve programming puzzles

You can always solve programming puzzles, and many such exist. Math oriented problems can be found at Project Euler, which is, probably, the most popular site for coding puzzles.

You should also try out code golf; a programming puzzle where programmers attempt to solve a given programming problem with the least amount of keystrokes. It can teach you many of the more esoteric and special features of the language, and you will have to think creatively about coding (and it is fun!).

Programming puzzles, mainly code golf, is found at codegolf.stackexchange.com.

5. Program

Start writing a program, from scratch. Design all of the architecture and implement it. Repeat.

Coding is best learned by coding. You will learn from your own mistakes, and finishing a project is motivating and much more fun than reading a book is.

6. Read and study code

Study famous software programs, such as the Linux kernel (be warned, it is huge). A good operating system for educational purposes is MINIX3. You can learn many new language idioms, and a thing or two about software architecture. Reading unfamiliar source code is daunting at first, but rewarding.

You can also increase your understanding of some API you use, or a programming language, by reading its implementation.

7. Hang out at programming sites and read blogs

Hanging out at different programming sites (such as forums and StackOverflow) will expose you to other programmers and at the same time, their knowledge.

Also, read blogs, maybe this (if you want) and preferably more. Good blogs are Joel on Software(although he doesn’t blog any more, jewels exist in the archives), Coding Horror and Lambda the Ultimate.

You should also follow news.ycombinator.com.

8. Write about coding

Start writing about coding on a blog, even if it is just for yourself. You can also write answers on different Q&A sites, forums or you can write tutorials at some sites (e.g. DreamInCode). When you write about coding, you want to make sure that use the correct terminology and know the why in order to explain problems and techniques. It also lets you reflect on your own programming knowledge and improve your English language skills, which is important in programming.

9. Learn low-level programming

Learning low-level programming and such languages is also useful for achieving a better understanding of the underlying machine. Check out C, and maybe even learn some processor’sAssembly language.

Learn how a computer executes a program and how an operating system works (at a high-level, at least). If you really want to go serious about low-level programming, you can read books on computer organization, operating systems, embedded systems, operating system driver development and so on (I’m reading such books at the moment).

10. Don’t rush to StackOverflow. Think!

So you have a problem with your code and you have been trying to solve it for half a minute. What do you (hopefully not) do? Run over to StackOveflow. Don’t. Spend a good deal of time trying to solve the problem on your own, instead. Take a paper and a pencil, start sketching a solution. If that doesn’t work, take a short break to keep your mind fresh and then try again.

If after spending an hour (or some other considerable amount of time, depending on the size of the problem) of trying to solve the problem, then you might go over to StackOverflow, but think on your own first.

C中的access函数

 

int   access(const   char   *filename,   int   amode); 
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。 
这个函数还可以检查其它文件属性: 
06     检查读写权限 
04     检查读权限 
02     检查写权限 
01     检查执行权限 
00     检查文件的存在性
而这个就算这个文件没有读权限,也可以判断这个文件存在于否
存在返回0,不存在返回-1

C函数
  函数名: access 
  功 能: 确定文件的访问权限 
  用 法: int access(const char *filename, int amode);
[编辑本段]access
  Synopsis
  #include <io.h>
  int _access(const char *path,int mode) ;
  Description
  The access function, when used with files, determines whether the specified file exists and can be accessed as specified by the value of mode. When used with directories, _access determines only whether the specified directory exists; since under Windows all directories have read and write access.
  The mode argument can be one of :
  00 Existence only
  02 Write permission
  04 Read permission
  06 Read and write permission 
  Returns
  Zero if the file has the given mode, -1 if an error occurs.
  Portability :
  Windows. Under Unix a similar function exists too.
  Note that lcc-win32 accepts both _access (Microsoft convention) and access.
  程序例: 
  

  1. #include <stdio.h> 
  2.   #include <io.h> 
  3.   int file_exists(char *filename); 
  4.   int main(void) 
  5.   { 
  6.   printf("Does NOTEXIST.FIL exist: %s\n", 
  7.   file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); 
  8.   return 0; 
  9.   } 
  10.   int file_exists(char *filename) 
  11.   { 
  12.   return (access(filename, 0) == 0); 
  13.   }

 

常量指针与指针常量

  首先,我告诉大家一个小规则,就是像这样连着的两个词,前面的一个通常是修饰部分,中心词是后面一个词,怎么说呢。就像这里的常量指针和指针常量。

  常量指针,表述为“是常量的指针”,它首先应该是一个指针。
  指针常量,表述为“是指针的常量”,它首先应该是一个常量。

   我再分开细细说明,常量指针,它是一个指针,什么样的指针呢?它是一个指向常量的指针,就是说我们定义了一个常量,比如 const int a=7; 那么我们就可以定义一个常量指针来指向它 const int *p=&a; 也可以分成两步,即 const int *p; p=&a; 那么它有什么作用呢?首先我们来说说常量的属性,因为我们的指针是指向常量的,常量和变量的变量的不同之处在于我们不能对其内容进行 操作,具体说就是修改,而我们的指针是什么,它的内容本身是一个地址,设置常量指针指向一个常量,为的就是防止我们写程序过程中对指针误操作出现了修改常 量这样的错误,应该如果我们修改常量指针的所指向的空间的时候,编译系统就会提示我们出错信息。总结一下,常量指针就是指向常量的指针,指针所指向的地址的内容是不可修改的。

  再 来说说指针常量,它首先是一个常量,再才是一个指针。常量的性质是不能修改,指针的内容实际是一个地址,那么指针常量就是内容不能修改的常量,即内容不能 修改的指针,指针的内容是什么呀?指针的内容是地址,所以,说到底,就是不能修改这个指针所指向的地址,一开始初始化,指向哪儿,它就只能指向哪儿了,不 能指向其他的地方了,就像一个数组的数组名一样,是一个固定的指针,不能对它移动操作,比如你使用 p++; 系统就会提示出错。但是它只是不能修改它指 向的地方,但这个指向的地方里的内容是可以替换的,这和上面说的常量指针是完全不同的概念。作一下总结,指针常量就是是指针的常量,它是不可改变地址的指针,但是可以对它所指向的内容进行修改。对了,忘了说说它怎么用,举个小例子 int a; int * const p=&a; 也可以分开写 int a; int * const p; p=&a;

  当然,你也可以定义个一个指向常量的指针常量,就把上面的两个综合一下,表示如下

const int a=7; const int * const p=&a;

  多上机试试,多揣摩一下,其实并不是很难理解。而且用我的方法也很好记,不是吗,呵呵。

bash的内部命令

 

bash命令解释套装程序包含了一些内部命令。内部命令在目录列表时是看不见的,它们由Shell本身提供。常用的内部命令有:echo, eval, exec, export, readonly, read, shift, wait和点(.)。下面简单介绍其命令格式和功能。

  1.echo

  命令格式:echo arg

  功能:在屏幕上显示出由arg指定的字串。

  2.eval

  命令格式:eval args

  功能:当Shell程序执行到eval语句时,Shell读入参数args,并将它们组合成一个新的命令,然后执行。

  3.exec

  命令格式:exec命令参数

  功能:当Shell执行到exec语句时,不会去创建新的子进程,而是转去执行指定的命令,当指定的命令执行完时,该进程(也就是最初的Shell)就终止了,所以Shell程序中exec后面的语句将不再被执行。

  4.export

  命令格式:export变量名 或:export变量名=变量值

  功能:Shell可以用export把它的变量向下带入子Shell,从而让子进程继承父进程中的环境变量。但子Shell不能用export把它的变量向上带入父Shell。

  注意:不带任何变量名的export语句将显示出当前所有的export变量。

  5.readonly

  命令格式:readonly变量名

  功能:将一个用户定义的Shell变量标识为不可变。不带任何参数的readonly命令将显示出所有只读的Shell变量。

  6.read

  命令格式:read变量名表

  功能:从标准输入设备读入一行,分解成若干字,赋值给Shell程序内部定义的变量。

  7.shift语句

  功能:shift语句按如下方式重新命名所有的位置参数变量,即$2成为$1,$3成为$2…在程序中每使用一次shift语句,都使所有的位置参数依次向左移动一个位置,并使位置参数$#减1,直到减到0为止。

  8.wait

  功能:使Shell等待在后台启动的所有子进程结束。wait的返回值总是真。

  9.exit

  功能:退出Shell程序。在exit之后可有选择地指定一个数位作为返回状态。

  10.“.”(点)

  命令格式:. Shell程序文件名

  功能:使Shell读入指定的Shell程序文件并依次执行文件中的所有语句。