OpenSource For You

The C library is perhaps the most widely reused library in the world. However, it has numerous flaws and inconsiste­ncies, from which we can learn.

-

Design is hard, and API design is harder. This is because applicatio­ns and systems are designed to be used, while in the case of APIs, we design them not just to be used but also reused. Applicatio­ns are designed for end customers to use; however, with the APIs in libraries, platforms and frameworks, the end user is another programmer who wants to get the work done via the API. There are more things to consider in API design than with applicatio­n design. For example, compatibil­ity issues (such as backward compatibil­ity) are an additional concern for an API designer. In frameworks and libraries, fixLnJ D buJ Ls GLIfiFulW whHn FoPSDrHG Wo fixLnJ WhH sDPH bug in a stand-alone applicatio­n. For example, if the bug fix LnYolYHs D FhDnJH Wo WhH SublLF LnWHrIDFH HxSosHG by WhH API, then the existing applicatio­ns written based on that interface will fail. Hence, the evolution of an API is harder than evolving applicatio­ns.

C is used in a wide range of devices, ranging from microwave ovens to air- planes. With the popularity of the C language and its widespread use, APIs in the C library have been used by millions of programmer­s worldwide over the last four decades. The C library has had a huge impact on the design of libraries in languages that arrived later. For example, the ‘ format string’ approach is not type- safe, but for formatted output, it is a very convenient approach. The C++ language provides a type- safe alternativ­e to formatted output, but that is not as convenient as the C ‘ format style’ approach to use. The Java language’s println approach is type- safe, but is not convenient. Hence, Java introduced printf with the ‘ format string’ approach in its library. Similarly, C# has format strings, and only its format specifier is slightly different; instead of the B symbol, it uses {} symbols. This is just one example of the influence of C library design on languages that came up later.

Given the influence and widespread use it enjoyed, it is surprising to find that the C library has numerous flaws and mistakes! So, it would be interestin­g for us to understand these mistakes and learn from them, so that we can avoid them in future.

NoWH WhH orGHr oI WhH firsW Wwo DrJuPHnWs Ior WhHsH. As you can see, the order is interchang­ed. As a programmer, you should remember which the source string is and which the destinatio­n string is, because if you get confused, you may introduce a subtle bug by copying the string from the destinatio­n to the source! That is why consistenc­y is an important factor in API design, and many C library functions are inconsiste­nt.

 ??  ?? S.G.Ganesh
S.G.Ganesh

Newspapers in English

Newspapers from India