The SKILL programming language augments Cadence core tool
functionality for Virtuoso and Allegro customers. It is also an
important development tool for internal Cadence services organizations
as well as Cadence product development groups. We see the value,
power, flexibility, and elegance of the language as an enabling tool for customizing and enhancing design environments. These
capabilities are made possible by the tight integration of the
SKILL programming language into the Cadence platform.
This post introduces an upcoming series of articles, SKILL for the Skilled,
which will attempt to better enable users to exploit the power and
elegance of this fun and interesting programming language.
WARNING: What you are about to read is HIGHLY OPINIONATED!
SKILL Functions: Short and Clear
SKILL programs are usually made up of functions. A function should be
short, clear, and express intent. Some programming languages force
the programmer to transform the software problem into what the
language can express, rather than allowing the programmer to transform
the language to fit the problem at hand. The unfortunate result is
often that the SKILL program looks like a C program, and is twice to
ten times as long as it needs to be. We'll look at this ability to
transform the language in upcoming articles.
To illustrate the idea that functions should be short and clear, here
are two different implementations of the same conceptual function.
The confusing one (#1) uses an imperative style. Avoid this style.
The second one (#2) uses a functional style. Without sacrificing
clarity, it expresses in two lines what the imperative style expresses
in nine lines. It is clearer, probably easier to debug, most certainly
more efficient computation-wise, and scales better to larger programs.
Implementation #1 -- needlessly confusing
procedure( abs_less_than_100(x) prog( (value) value = abs(x) if( value < 100 then return(t) else return(nil) ) ; if ) ; prog) ; procedure
(procedure (abs_less_than_100 x) (abs x) < 100)
What were the programmers thinking?
What are the problems of Implementation #1? What was programmer #1's
thought process? He was probably trying to think like a Von Neumann
machine -- in terms of an arithmetic unit and moving values around
between registers until the goal is achieved. Programmer #2 was
probably trying to express a mathematical expression.
A more natural way to think
I claim that the mathematical evaluation model is an easier, more
natural way for humans to think than trying awkwardly to think like a
machine that's moving data between registers. Don't try to make
the problem harder than it is.
Aside from the two very different ways of thinking, there are several
other issues I have with implementation #1.
The SKILL language is on the one hand easy to learn and easy to use
for simple use-once-and-discard scripting tasks. On the other hand
the power and flexibility of the language is evident when experienced
programmers develop well designed, high quality SKILL based software
applications. The elegance of the SKILL language is often
underestimated. A well written SKILL program is easy to understand,
takes fewer lines of code to implement, and incurs shorter development
times than with most other language alternatives, assuming the
developers understand the tools they are using.
Until now, it has been somewhat difficult to find insightful articles
written about SKILL and how to apply it to day to day problems. I hope
this series of articles enables you to get more benefit and enjoyment
out of the SKILL programming language.
as to your comment about PCell code which is unmanageably long because of dependency management, I could not agree more. The OODI (object oriented device infrastructure) which can be standard in 616, but is available to early customer who request it along with 615, will address many of these problems.
Using OODI, devices are implemented as SKILL++ classes, not in terms of pcDefinePCell. This means that (1) by default PCell code will be lexically scoped, (2) code reuse can be enforced to a limited extent by the SKILL++ object system in terms of the class hierarchy, and (3) the base classes such as pcoStandardDevice will provide lots of powerful methods for easily creating complex PCells with very little customer code necessary.
I think this will be a good step toward decreasing code size of customer PCells.
Hi Damien, thanks for the positive feedback and the great questions.
Yes, destructuringBind, labels, and flet will be standard in 615. The in the first release flet and labels will refuse to run (runtime error) if they are encountered in non-scheme code. If the functions are needed in dynamically scoped SKILL code, an enhancement CCR will need to be filed. However, destructuringBind will work in both dialects.
For anyone who wants to find out more of flet, labels, and destrucuringBind, the will be discussed in more detail in upcoming articles on this blog. In the meantime, you can take a look at the following web pages to see how they work in Common Lisp.
Or you can do a simple google search for: lisp flet labels destructuring-bind
Jim: Flet/labels in 6.1.5? That's great news, indeed!
I believe one of the reasons a lot of the SKILL code found in the wild is so cluttered is that people are trying to avoid external dependencies in pcells... and the lack of support for local functions (lambda is very unwieldy in pure SKILL) pushes them to write loooooooong and repetitive bodies of code.
It also makes your article very to-the-point; a nice followup (when 6.1.5 is out) would be to show how to write a clean (but still standalone) pcell using these constructs to define short local functions!
P.-S. -- Are flet/labels going to be available in both language modes? Is tracing local functions going to be possible?
If you use a text editor that understand parathesis it does not really matter where the paran is placed. An example of that is UltraEdit that also have a skill plugin, read the skill post at www.cadence.com/.../17154.aspx
Thanks for the response Andrew. Different people have different experience of course, but the problem which I've seen more often is that people write functions which contain too much clutter, not that people write functions which are too terse. This is the problem I was addressing here.
About the close paren: Yes, if it is too far away from the open paren it can indeed be a problem. But the advise I'd give in that case is "Don't put the close paren very far away from the opening paren." If your function is too long to fit on a screen, don't get a bigger screen, just split the function. This also means you have to think about how to refactor it and find appropriate names for the components. If you don't want to make the component functions global, you can make local functions for which there are very nice new syntaxes for in 615: flet and labels.
A couple of thoughts on Jim's post.
I don't entirely agree with the statement about lines with just close parentheses. I think there can be some benefit in having them on separate lines as this can encourage readability of the code, provided the indentation is consistent. Similarly commenting the close parenthesis when it is a long way from the open parenthesis can help a reader (particularly one who is less familiar with SKILL) understand the code. But commenting every close is unnecessary, of course - the indentation should allow you to follow the code.
Conciseness is a laudable quality, but should not be the only aim. It's always important to ensure that code can be easily comprehended, and so if that means using an unnecessary variable in order to self-document the code, that can be a good thing. Of course in this very simple example, there is absolutely no need to have the prog, the if, or the local variable; the simplified function is just as easy to understand and is more concise.
Just in case anyone is confused by the semi-LISP syntax of the improved example, you could equally well writ e this as:
Both are equivalent. Similarly true LISPers would write this as:
(defun abs_less_than_100 (x)
(lessp (abs x) 100)
which is also equivalent!
The key points that I see from Jim's post is that SKILL is a functional programming language - everything you do is a function - and so it makes sense to think in terms of functions which return things. That's quite different from languages like C - so in SKILL, if(), case(), while(), foreach() etc all have return values - so you might as well take advantage of that!