8 ms·
> Ultimately this: > FILE * test_file = fopen(“/tmp/test.txt”, “w+”); > Should become something like this: > create file /tmp/test.txt for input and output a
by crazygringo 8y ago
> Ultimately this:
> FILE * test_file = fopen(“/tmp/test.txt”, “w+”);
> Should become something like this:
> create file /tmp/test.txt for input and output as test_file
> Syntax highlighting should work instead of syntax notation just fine.
I couldn't disagree more.
The first example is easily scannable visually -- a variable is being created from a function call. I can tell because my eyes immediately notice the middle "=" first (easy to scan without reading) and the "(...)" in the second half (also easy to scan).
The second example is all words without punctuation, which requires me to read the entire thing word-for-word to figure out what it's doing.
We certainly shouldn't aspire to regex-like syntax for programming... but we also shouldn't aspire to prose. A healthy balance of words, punctuation, and whitespace/indentation helps to let our eyes understand the structure of code at a glance.
I'd argue that C-style syntax actually achieves this quite well, although I'm also a fan of named (as opposed to ordered) function arguments.
- justinator 8y agoI think the OP perhaps wants to look at Apple Script?
- jandrese 8y agoThe OP wants a modernized COBOL.
- Vinnl 8y agoIn fact, that's what they say after clicking the buttons at the bottom - which are actually part of the article.
- reitanqild 8y agoActually not if one reads carefully.
- Vinnl 8y agoWell all right, they don't really want COBOL - they're saying that that's what they were describing as something they wanted. But my point was primarily that people probably missed that they had to click the buttons to read that.
- qu4z-2 8y agoAs far as I can tell, the OP wants people to stop inventing languages and "just write good code". They're deliberately describing COBOL as exciting, new and modern to make their point.
- jacobolus 8y agoYes, this proposal is basically AppleScript. AppleScript is (relatively) easy for non-programmers to read and understand, because it is built on natural language. Unfortunately AppleScript is a huge pain to write, because as a programming language it is still quite strict about what type of syntax it will accept. It also is fairly limited, because speccing a natural language programming vocabulary/grammar gets increasingly difficult as you start adding features. As a result even the best AppleScript programs are not concise at all, with limited use of abstraction. Most AppleScript programs are cobbled together by copy/pasting code found on the internet, and are full of bugs.
- MauranKilom 8y agoIn my experience, the problem people have with learning programming is not syntax or abstraction - it's thinking like the abstract machine. Or in other words, understanding that having an array and a loop in your code isn't enough to make the computer understand and do what you want. Basically, the thing that the PB&J exact instructions challenge teaches.
- fouc 8y agoIt's interesting you mention an array and a loop, because those can be separate abstractions too. no need to think about loops: array.each {|x| puts x} need think about loops: for i in 0...array.length do puts array[i] end
- kbp 8y agoThe first example saves you from thinking about indexing; arrays and loops are relevant in both.
- kbenson 8y agoI agree somewhat, but I think it's important to consider that the ease of reading c-style syntax you experience is probably greatly helped by the wide adoption it's seen of at least some of its features and the repeated exposure you've had to this point, as most of us have. There is a choice to be made as to whether amateur learning should be optimized (not that their example would be the result), or or a greater tie-in with the existing programming ecosystem should be. Both have their trade-offs, similar to the question of whether we optimize ease of learning or ease of use for experienced programmers (think BASIC vs APL).
- j2kun 8y agoIndeed, there's a reason that SQL statements still need formatting and keyword capitalization hints to make it readable.
- setr 8y agoWhat language doesn’t need formatting to be readable? Have you tried reading whitespace-stripped C/js? And the caps hint is the same as syntax highlighting... its not even that useful if you have highlighting, but boy is it useful when you don’t
- j2kun 8y agoThat's my point (and the opposite of the author's point)
- warent 8y agoI wholeheartedly agree with you on this. `create file /tmp/test.txt for input and output as test_file` To me, this does not explain what's happening here with any clarity. I'm left feeling overwhelmed with uncertainty and ambiguity. Is there an iterable being acted on? Is this blocking? Is it creating a variable? Two variables? What type is /tmp/test.txt when it has no quotation marks, and how does it handle spaces or concatenation/methods? Those questions are just the tip of the iceberg. It goes on and on. Not only that, but you're actually saving time by utilizing symbols rather than words. There's so much decoding that goes into reading a whole entire word/sentence rather than just flowing and gliding along symbols and keywords. There's a reason why mathematics in general typically uses symbols rather than these huge verbose chunks that are open to interpretation.
- coldtea 8y ago>Is there an iterable being acted on? Is this blocking? Is it creating a variable? Two variables? What type is /tmp/test.txt when it has no quotation marks, and how does it handle spaces or concatenation/methods? Well, if you knew the language, you'd have answer to all of those questions. Plus, if you didn't know C, you'd be baffled by the other example as well...
- michaelmrose 8y agoFor any reasonably complex example its not at all clear that this is so. Being more english like is actually a hardship not a benefit because naturally language is famously ambiguous and difficult to decode. Either your language is incredibly complex or it understands a very stilted subset of actual normal language that only happens to look like natural language and you have to remember to use that stilted subset in which case what is the benefit of this vs foo = bar. Regarding complex language we seem remarkably bad at simple things.
- ArchTypical 8y ago> Being more english like is actually a hardship not a benefit because naturally language is famously ambiguous and difficult to decode The rules are not any worse to express the exact same operations and relationships. English would need to be augmented to necessarily express the same things. The syntax would change, but thats the point. It doesnt solve anything. Making programs more verbose and approachable is a common theme in scripting languages already. How far is too far?
- deleted 8y ago[deleted]
- freeone3000 8y agoWhile this is a valid criticism that I agree with, I feel as if it misses the forest for the trees. The problem is entirely that the time is spent arguing over minor differences in syntax and style, while spending comparatively little time on the bigger questions of testing, security, updates, and ease-of-use of the end product. No user of software particularly cares if it's written in C or COBOL, they care whether it reboots at midnight to apply security updates, losing their work, or spends an extra three minutes a day because it has to contact a webservice.
- cultus 8y agoVery much agree. Programming notation, like math, is supposed to be easy to convey exact meaning, unlike human language. Every attempt there has been to make code look like English hasn't worked out well. SQL, for example, is incredibly verbose, with complex syntax. This obscures what is otherwise very good semantics. I think this is why a lot of people hate writing queries.
- Guthur 8y agoAnd yet after 30+ years no one had adequately managed to replace it. God help us if it's one of those json based abominations. My main complaint with sql is that it can be somewhat difficult top make DRY.
- gaius 8y agoCTEs can go a long way toward that, as can stored procs
- dragonwriter 8y agoAs can views.
- danidiaz 8y agoLATERAL joins can help with reusing calculations https://www.periscopedata.com/blog/reuse-calculations-in-the-same-query-with-lateral-joins https://www.periscopedata.com/blog/reuse-calculations-in-the...
- infinite8s 8y agoWow that's a bad example. Any decent query engine (which I'm assuming Postgres has) would reuse common subexpressions.
- danidiaz 8y agoEven if duplicate expressions are optimized by the engine, they hurt the readability and maintainability of the query, especially if they are big and complex.
- MattRix 8y agoSomeone didn't finish reading the article...
- gary__ 8y agoIn our defemse, we also had to click a button, who really isn't learning from their time in the modern world! /S
- miguelrochefort 8y ago> The second example is all words without punctuation, which requires me to read the entire thing word-for-word to figure out what it's doing. Do you think that's also a problem with natural languages (e.g. English)? Should we switch to a more readable natural language with a syntax inspired by programming languages (or even visual programming languages)?
- red75prime 8y agoNatural languages don't usually convey precise set of instructions to be executed, or target a system that has no common sense, situation awareness, and other human traits. The purposes of natural and computer languages are quite different, so it doesn't make much sense to model one after another. There were attempts to make more precise languages (Lojban, for example), but they never took off. Maybe because it's too tiring to precisely describe meaning, which can be inferred from a context with sufficient probability or clarified by asking questions.
- munchbunny 8y agoI think the goal in general should be to minimize conceptual depth and maximize predictability for the problem domain you are trying to address. I dislike the C style for several reasons: > FILE * test_file = fopen(“/tmp/test.txt”, “w+”); First, you have to understand the implications of it being a pointer, which includes the little warning light in your head about ownership and allocation/deallocation. Then you have to remember that "w+" translates to "write in append mode". The fact that it's a string means you know it by memorization. But also there are warning lights in your head about text encoding... just standard things you're trained to be vigilant about. Where you can avoid triggering those reactions, I think it's worth trying. These days we have the help of IDE's as memory aids, so for things like "w+" I prefer enums so that a tap of the auto-complete button shows you "write mode" and "append mode" options. I suppose if I were to have any marginally controversial opinion on this topic, it's that I believe we should be embracing IDE's as "portable stack overflows" and designing languages with IDE assistance in mind.
- setr 8y ago>First, you have to understand the implications of it being a pointer, which includes the little warning light in your head about ownership and allocation/deallocation Thats a semantic issue, not a syntax/style one. If your language has pointer semantics, you’d need to a way to access it with either proposed styles, and the same warning light should appear regardless. The w+ example is much more relevant, as it could be expressed more clearly and well-defined (eg enum with full name). But all you could do with the pointer syntax is say FILE POINTER test_file, and gain nothing, because the “*” syntax isn’t at fault here
- deleted 8y ago[deleted]
- OJFord 8y agoIt looks like AppleScript, which is an absolute nightmare to have to use.
- Const-me 8y agoAnother thing is, with the proposed syntax it's very easy to screw up. Creating a file named "test" has the same syntax as creating a file with name from the variable "test".
- cm2187 8y agoBut are’t you describing familiarity rather than readability? Ask a non programmer if he thinks the syntax of c code feels logical and natural.
- red75prime 8y agoAsk me if I think that the syntax of Chinese language feels..., well, like anything at all (punctuation marks are western influence).
- cm2187 8y agoYeah. But if you ask a VB or python programmer who never wrote in a c-style syntax, you will probably get the opposite opinion.
- scardine 8y agoPython's way is a good compromise IMHO: with open("/tmp/test.txt", "w+") as test_file: do_something_with(test_file) And you get test_file closed for free at the end of the block.
- satyenr 8y agoCompletely agree. A balance is needed between the tenseness of Perl and the verbosity of AppleScript. Too compact, and the language becomes a pain to read — although I am sure the author feels clever at having accomplished so much in so little code. On the other side, too verbose and it is a pain to write and read. I absolutely hate reading through or writing pages upon pages of code to accomplish a trivial task. Perhaps that is the reason languages like Python have been so successful. They seem to strike a good balance. I am not suggesting they are perfect by any means — they have their own fair share of compromises, but they do the job well enough. And I certainly don’t want to be writing COBOL in 21st century. :-)
- alephnil 8y agoWhich of these forms you use does not matter all that much. They both have the same semantics where a file is opened, and it is up to the programmer to remember to close it. What actually is a an improvement is Common Lisp's with-open-file or similarly, python's with: with open("somefile.dat", "wb") as f: f.write(somevar) which automatically closes the file when it leaves the scope.
- yellowapple 8y agoI disagree. The only reason why the first example might be "easier to scan" is because the reader happens to already have experience with that language. COBOL got a bad rap for being "too verbose", but that kind of verbosity paired with a language that actually supports modern techniques for code organization and modularity would be a godsend in this new era of blurring lines between designing software and designing businesses. The need for programs that can be understood by anyone without a full-blown programming background hasn't gone away. It's worth noting that what the author seeks is already possible with a language like Tcl, or even with a shell language like Bourne or one of its descendants. Sure, most programs don't do that (probably because there aren't very many getopts-like libraries do parse that sort of argument list), but it's possible nonetheless.