AffairWithCPP.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  5. <head>
  6. <!-- 2022-01-27 Thu 11:37 -->
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <title>An Affair with C++</title>
  10. <meta name="generator" content="Org mode" />
  11. <meta name="author" content="Girish" />
  12. <style type="text/css">
  13. <!--/*--><![CDATA[/*><!--*/
  14. .title { text-align: center;
  15. margin-bottom: .2em; }
  16. .subtitle { text-align: center;
  17. font-size: medium;
  18. font-weight: bold;
  19. margin-top:0; }
  20. .todo { font-family: monospace; color: red; }
  21. .done { font-family: monospace; color: green; }
  22. .priority { font-family: monospace; color: orange; }
  23. .tag { background-color: #eee; font-family: monospace;
  24. padding: 2px; font-size: 80%; font-weight: normal; }
  25. .timestamp { color: #bebebe; }
  26. .timestamp-kwd { color: #5f9ea0; }
  27. .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
  28. .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
  29. .org-center { margin-left: auto; margin-right: auto; text-align: center; }
  30. .underline { text-decoration: underline; }
  31. #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  32. p.verse { margin-left: 3%; }
  33. pre {
  34. border: 1px solid #ccc;
  35. box-shadow: 3px 3px 3px #eee;
  36. padding: 8pt;
  37. font-family: monospace;
  38. overflow: auto;
  39. margin: 1.2em;
  40. }
  41. pre.src {
  42. position: relative;
  43. overflow: visible;
  44. padding-top: 1.2em;
  45. }
  46. pre.src:before {
  47. display: none;
  48. position: absolute;
  49. background-color: white;
  50. top: -10px;
  51. right: 10px;
  52. padding: 3px;
  53. border: 1px solid black;
  54. }
  55. pre.src:hover:before { display: inline;}
  56. /* Languages per Org manual */
  57. pre.src-asymptote:before { content: 'Asymptote'; }
  58. pre.src-awk:before { content: 'Awk'; }
  59. pre.src-C:before { content: 'C'; }
  60. /* pre.src-C++ doesn't work in CSS */
  61. pre.src-clojure:before { content: 'Clojure'; }
  62. pre.src-css:before { content: 'CSS'; }
  63. pre.src-D:before { content: 'D'; }
  64. pre.src-ditaa:before { content: 'ditaa'; }
  65. pre.src-dot:before { content: 'Graphviz'; }
  66. pre.src-calc:before { content: 'Emacs Calc'; }
  67. pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  68. pre.src-fortran:before { content: 'Fortran'; }
  69. pre.src-gnuplot:before { content: 'gnuplot'; }
  70. pre.src-haskell:before { content: 'Haskell'; }
  71. pre.src-hledger:before { content: 'hledger'; }
  72. pre.src-java:before { content: 'Java'; }
  73. pre.src-js:before { content: 'Javascript'; }
  74. pre.src-latex:before { content: 'LaTeX'; }
  75. pre.src-ledger:before { content: 'Ledger'; }
  76. pre.src-lisp:before { content: 'Lisp'; }
  77. pre.src-lilypond:before { content: 'Lilypond'; }
  78. pre.src-lua:before { content: 'Lua'; }
  79. pre.src-matlab:before { content: 'MATLAB'; }
  80. pre.src-mscgen:before { content: 'Mscgen'; }
  81. pre.src-ocaml:before { content: 'Objective Caml'; }
  82. pre.src-octave:before { content: 'Octave'; }
  83. pre.src-org:before { content: 'Org mode'; }
  84. pre.src-oz:before { content: 'OZ'; }
  85. pre.src-plantuml:before { content: 'Plantuml'; }
  86. pre.src-processing:before { content: 'Processing.js'; }
  87. pre.src-python:before { content: 'Python'; }
  88. pre.src-R:before { content: 'R'; }
  89. pre.src-ruby:before { content: 'Ruby'; }
  90. pre.src-sass:before { content: 'Sass'; }
  91. pre.src-scheme:before { content: 'Scheme'; }
  92. pre.src-screen:before { content: 'Gnu Screen'; }
  93. pre.src-sed:before { content: 'Sed'; }
  94. pre.src-sh:before { content: 'shell'; }
  95. pre.src-sql:before { content: 'SQL'; }
  96. pre.src-sqlite:before { content: 'SQLite'; }
  97. /* additional languages in org.el's org-babel-load-languages alist */
  98. pre.src-forth:before { content: 'Forth'; }
  99. pre.src-io:before { content: 'IO'; }
  100. pre.src-J:before { content: 'J'; }
  101. pre.src-makefile:before { content: 'Makefile'; }
  102. pre.src-maxima:before { content: 'Maxima'; }
  103. pre.src-perl:before { content: 'Perl'; }
  104. pre.src-picolisp:before { content: 'Pico Lisp'; }
  105. pre.src-scala:before { content: 'Scala'; }
  106. pre.src-shell:before { content: 'Shell Script'; }
  107. pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
  108. /* additional language identifiers per "defun org-babel-execute"
  109. in ob-*.el */
  110. pre.src-cpp:before { content: 'C++'; }
  111. pre.src-abc:before { content: 'ABC'; }
  112. pre.src-coq:before { content: 'Coq'; }
  113. pre.src-groovy:before { content: 'Groovy'; }
  114. /* additional language identifiers from org-babel-shell-names in
  115. ob-shell.el: ob-shell is the only babel language using a lambda to put
  116. the execution function name together. */
  117. pre.src-bash:before { content: 'bash'; }
  118. pre.src-csh:before { content: 'csh'; }
  119. pre.src-ash:before { content: 'ash'; }
  120. pre.src-dash:before { content: 'dash'; }
  121. pre.src-ksh:before { content: 'ksh'; }
  122. pre.src-mksh:before { content: 'mksh'; }
  123. pre.src-posh:before { content: 'posh'; }
  124. /* Additional Emacs modes also supported by the LaTeX listings package */
  125. pre.src-ada:before { content: 'Ada'; }
  126. pre.src-asm:before { content: 'Assembler'; }
  127. pre.src-caml:before { content: 'Caml'; }
  128. pre.src-delphi:before { content: 'Delphi'; }
  129. pre.src-html:before { content: 'HTML'; }
  130. pre.src-idl:before { content: 'IDL'; }
  131. pre.src-mercury:before { content: 'Mercury'; }
  132. pre.src-metapost:before { content: 'MetaPost'; }
  133. pre.src-modula-2:before { content: 'Modula-2'; }
  134. pre.src-pascal:before { content: 'Pascal'; }
  135. pre.src-ps:before { content: 'PostScript'; }
  136. pre.src-prolog:before { content: 'Prolog'; }
  137. pre.src-simula:before { content: 'Simula'; }
  138. pre.src-tcl:before { content: 'tcl'; }
  139. pre.src-tex:before { content: 'TeX'; }
  140. pre.src-plain-tex:before { content: 'Plain TeX'; }
  141. pre.src-verilog:before { content: 'Verilog'; }
  142. pre.src-vhdl:before { content: 'VHDL'; }
  143. pre.src-xml:before { content: 'XML'; }
  144. pre.src-nxml:before { content: 'XML'; }
  145. /* add a generic configuration mode; LaTeX export needs an additional
  146. (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
  147. pre.src-conf:before { content: 'Configuration File'; }
  148. table { border-collapse:collapse; }
  149. caption.t-above { caption-side: top; }
  150. caption.t-bottom { caption-side: bottom; }
  151. td, th { vertical-align:top; }
  152. th.org-right { text-align: center; }
  153. th.org-left { text-align: center; }
  154. th.org-center { text-align: center; }
  155. td.org-right { text-align: right; }
  156. td.org-left { text-align: left; }
  157. td.org-center { text-align: center; }
  158. dt { font-weight: bold; }
  159. .footpara { display: inline; }
  160. .footdef { margin-bottom: 1em; }
  161. .figure { padding: 1em; }
  162. .figure p { text-align: center; }
  163. .inlinetask {
  164. padding: 10px;
  165. border: 2px solid gray;
  166. margin: 10px;
  167. background: #ffffcc;
  168. }
  169. #org-div-home-and-up
  170. { text-align: right; font-size: 70%; white-space: nowrap; }
  171. textarea { overflow-x: auto; }
  172. .linenr { font-size: smaller }
  173. .code-highlighted { background-color: #ffff00; }
  174. .org-info-js_info-navigation { border-style: none; }
  175. #org-info-js_console-label
  176. { font-size: 10px; font-weight: bold; white-space: nowrap; }
  177. .org-info-js_search-highlight
  178. { background-color: #ffff00; color: #000000; font-weight: bold; }
  179. .org-svg { width: 90%; }
  180. /*]]>*/-->
  181. </style>
  182. <script type="text/javascript">
  183. /*
  184. @licstart The following is the entire license notice for the
  185. JavaScript code in this tag.
  186. Copyright (C) 2012-2019 Free Software Foundation, Inc.
  187. The JavaScript code in this tag is free software: you can
  188. redistribute it and/or modify it under the terms of the GNU
  189. General Public License (GNU GPL) as published by the Free Software
  190. Foundation, either version 3 of the License, or (at your option)
  191. any later version. The code is distributed WITHOUT ANY WARRANTY;
  192. without even the implied warranty of MERCHANTABILITY or FITNESS
  193. FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  194. As additional permission under GNU GPL version 3 section 7, you
  195. may distribute non-source (e.g., minimized or compacted) forms of
  196. that code without the copy of the GNU GPL normally required by
  197. section 4, provided you include this license notice and a URL
  198. through which recipients can access the Corresponding Source.
  199. @licend The above is the entire license notice
  200. for the JavaScript code in this tag.
  201. */
  202. <!--/*--><![CDATA[/*><!--*/
  203. function CodeHighlightOn(elem, id)
  204. {
  205. var target = document.getElementById(id);
  206. if(null != target) {
  207. elem.cacheClassElem = elem.className;
  208. elem.cacheClassTarget = target.className;
  209. target.className = "code-highlighted";
  210. elem.className = "code-highlighted";
  211. }
  212. }
  213. function CodeHighlightOff(elem, id)
  214. {
  215. var target = document.getElementById(id);
  216. if(elem.cacheClassElem)
  217. elem.className = elem.cacheClassElem;
  218. if(elem.cacheClassTarget)
  219. target.className = elem.cacheClassTarget;
  220. }
  221. /*]]>*///-->
  222. </script>
  223. </head>
  224. <body>
  225. <div id="content">
  226. <div id="table-of-contents">
  227. <h2>Table of Contents</h2>
  228. <div id="text-table-of-contents">
  229. <ul>
  230. <li><a href="#org444df9c">1. An Affair with C++</a>
  231. <ul>
  232. <li><a href="#orgaec946e">1.1. Falling in love</a></li>
  233. <li><a href="#orga91db2f">1.2. The trauma</a></li>
  234. <li><a href="#org37ebed7">1.3. Aftermath</a></li>
  235. </ul>
  236. </li>
  237. </ul>
  238. </div>
  239. </div>
  240. <div id="outline-container-org444df9c" class="outline-2">
  241. <h2 id="org444df9c"><span class="section-number-2">1</span> An Affair with C++</h2>
  242. <div class="outline-text-2" id="text-1">
  243. </div>
  244. <div id="outline-container-orgaec946e" class="outline-3">
  245. <h3 id="orgaec946e"><span class="section-number-3">1.1</span> Falling in love</h3>
  246. <div class="outline-text-3" id="text-1-1">
  247. <p>
  248. It was in college, when I was studying computer science that I first
  249. learnt C++ as part of the curriculum. Prior to C++, I had studied how to
  250. program using C. C++ was (or still is) considered to be an improvement
  251. to the C language. I remember reading Stephen Prata as the textbook
  252. and Lippman as the reference for learning C++. The course was called
  253. "Object Oriented Programming using C++". This meant a paradigm shift
  254. from the erstwhile imperative programming (using a language like C).
  255. We were taught, as part of the course, to think in terms of <i>objects</i>.
  256. Real world objects to be precise. It could be abstract too. Jargon such as inheritance, polymorphism and
  257. encapsulation became a parlance. A parlance associated with object
  258. orientation. I was wondering back then, "Why C++? when C could do it"
  259. The programming constructs such as a <i>class</i> in C++ seemed alien. I
  260. started off with rewriting C programs in C++. It was an easier way to learn the
  261. syntax and features of a new programming language. Rewrite. I remember
  262. writing simple programs for calculating simple interest, bank account (just
  263. deposit, withdraw and interest calculation) and so on. Gradually, the
  264. object oriented features were introduced and programs for the same
  265. were implemented. I found C++ to be a little simpler to understand.
  266. </p>
  267. </div>
  268. </div>
  269. <div id="outline-container-orga91db2f" class="outline-3">
  270. <h3 id="orga91db2f"><span class="section-number-3">1.2</span> The trauma</h3>
  271. <div class="outline-text-3" id="text-1-2">
  272. <p>
  273. C was a horror when it came to pointers, function pointers,
  274. multi-dimensional arrays, and implementing higher level data structures like trees,
  275. dictionaries etc. I had real trouble writing programs for implementing
  276. data structures. Huffman's algorithm in particular was a real challenge. Till date,
  277. I have not been able to implement it in either C or C++. Joel Spolsky,
  278. a software developer from New York, who created StackOverflow.com,
  279. states: 'programming is an <i>aptitude</i>' in one of his blogs. The
  280. real mettle of a programmer lies in the ability to think through
  281. abstractions. Two things that matter the most according to his blog are:
  282. Pointers and Recursion. He fails to understand why most people cannot
  283. think through these abstractions. It is probably an innate ability of
  284. a person and not something that one can practice and acquire. I would even
  285. go to an extent of calling it a <i>talent</i>. One can acquire skills through
  286. practice but to become a successful programmer, say someone like Linus
  287. Torvalds, one has to have this in-born ability.
  288. Back to C++, I did manage to get good grades in that course, the only
  289. challenge with C++ was friend functions. Why befriend someone when you
  290. can acquaint? Bjarne Stroustrup, the creator of C++, may have a strong
  291. reasoning behind that. Bjarne's talk on Big Think channel of YouTube
  292. was inspiring. I found his way of working noteworthy. He would use a
  293. small laptop, eleven or thirteen inches, not more than that, to
  294. write programs during his travels, and use a headphone to listen to a
  295. wide collection of music while programming. I would call Torvalds,
  296. Stroustrup and their likes as 'Celebrity Artists'. Artists who hone and
  297. master the art of computer programming and wield influence on a lot of
  298. fellow programmers. I remember a college professor of mine, who
  299. used C++ as a language of choice for understanding abstractions. From
  300. machine level to the application level: C++ did it all. Things such as
  301. 'name mangling' comes to my mind. He had worked at Yahoo, prior to
  302. joining our college. I remember him saying -
  303. "The purpose of inheritance is to avoid if-else conditions in the
  304. program". I couldn't counter that argument till date.
  305. On the contrary, it was reaffirmed by one of my senior
  306. colleagues at work, years later. Standard template library (STL) was a life
  307. saviour as it provided all the data structures that a C++ programmer
  308. would ever need. This was the case, at least back in 2009. After that, I learnt
  309. Java and never touched C++ for at least a decade to come.
  310. </p>
  311. </div>
  312. </div>
  313. <div id="outline-container-org37ebed7" class="outline-3">
  314. <h3 id="org37ebed7"><span class="section-number-3">1.3</span> Aftermath</h3>
  315. <div class="outline-text-3" id="text-1-3">
  316. <p>
  317. During 2018-19, I was part of Thirty Meter Telescope project's Observatory software quality
  318. assurance team, wherein I felt the urge to write some C++ code. I took
  319. up the task of porting objects written in Scala/Java to C++. Some interfaces
  320. were needed for the Event services, as part of the observatory
  321. software. After that, when I moved to another organisation and started working on
  322. Cisco WebEx teams software, I had tried to use C++ for a certain
  323. feature called 'Buttons and Cards'. I had to meddle with C++ code for
  324. that. I gave up after a week or so. The cognitive load of going
  325. through files of C++ code was overwhelming me. It wasn't the C++ that
  326. I had learnt in college; C++ 11, 17 were in vogue now. It had asynchronous
  327. functions and weird callbacks. Tad harder to understand using a debugger. I resorted
  328. to Java and JavaScript, the languages which almost anyone can program using,
  329. without many hassles. I am an avid gamer and most of AAA titles
  330. released are written using C++. The language for building modern day
  331. console games is C++. I remember tutoring fundamentals of Python
  332. programming to Prince, a thirteen year old kid from USA, a year ago,
  333. who said - "Minecraft in C++ is faster than Minecraft in Java". He
  334. wanted to learn C++ so that he could tweak Minecraft code. I was
  335. shocked and perplexed. I initiated C++,
  336. starting with the usual 'Hello world' program. The verbosity of C++ as
  337. compared to say Python, made it hard for Prince to write programs. Prince and I
  338. were used to the Python's bonhomie. Both of us struggled at the
  339. beginning, later we decided to learn something else.
  340. </p>
  341. </div>
  342. </div>
  343. </div>
  344. </div>
  345. <nav class="right">
  346. <a href="telltaleOfTypewriter.html"><img src="assets/img/previous.jpg" alt="Previous"></a>
  347. <a href="index.html"><img src="assets/img/home.jpg"></a>
  348. <a href="CritiqueOfCPP.html"><img src="assets/img/next.jpg" alt="Next"></a>
  349. </nav>
  350. <div id="postamble" class="status">
  351. <p class="author">Author: Girish</p>
  352. <p class="date">Created: 2022-01-27 Thu 11:37</p>
  353. <p>Copyright &copy; 2019 to present, Girish M <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img
  354. alt="Creative Commons License" style="border-width:0" src="assets/img/cc.png" /></a><br />This work is licensed
  355. under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons
  356. Attribution 4.0 International License</a>. The source for this web-page can be found <a
  357. href="https://notabug.org/girishm/girishm.nfshost.com/src/test/AffairWithCPP.html">here</a>
  358. </p>
  359. </div>
  360. </body>
  361. </html>