Comments (7)
Counterpoint: C#
Historically, that example in C# looked like
int loop_over_global() {
return 1
}
But later they explicitly added less-noisy syntax, so one can now write
int loop_over_global() => 1;
Boats did a great job of elaborating on different facets of "explicit" in https://boats.gitlab.io/blog/post/2017-12-27-things-explicit-is-not/ -- can you elaborate on which things you're most interested in here?
from cone.
@scottmcm I find that c# syntax bad, Dart has introduced the same convenience syntax and it makes it harder to just look at some code and speed read it with a single glance. I have no problem with implicitness as long as it makes reading code more obvious or faster or just as fast. For example I would never complain that on the lefthand side the type is missing in var x = 5;
. That's the kind of stuff that is okay by me. Code has to be obvious. Implicit returns just like the ends of blocks are important locations in code. It should be obvious where they are. When all languages constructs start to look the same, people have a harder time reading code quickly. It's like making a GUI flat, or removing all the icons from a gui or painting all the strawberries on a cake the same color as the cake. There are not that many different constructs in a language, they are allowed to look different in fact.. they should.
For the same reason I told the ziglang author: public/private is irrelevant for most code, lets make that implicit. It's okay to be implicit with that, removing those keywords removes so much needless text on the page and makes reading faster. Whether something is public or private is so rarely important while you are reading code, it's like some metadata if you ever decide to use it from some completely different location. It's crazy to include that in the source code in visible form.
So you see hopefully where I'm coming from, I'm not against implicit infered meaning at all. But it needs to help with reading speed and be obvious.
I had this example:
pub const Id = enum {
Return,
Const,
Ref
};
Now imagine for a second if it looked like this instead (forget what you would lose in terms of features, just imagine if for some reason this would be just as powerful)
Id = enum {
Return,
Const,
Ref
}
It is so painfully obvious, it's almost offensive how simple it looks right? Well that's where the goal should be. Offensively simple code. I look at this and there is absolutely not a single question I have about it.
from cone.
Thanks for the feedback. I will keep your concerns in mind. I can assure you that none of my design decisions result from wanting to make Cone more Pythony or to save keystrokes.
The good news for both your suggestions, is that return may always be explicitly specified and one may explicitly specify curly braces, which turns off significant indentation. So your code can definitely follow the conventions you prefer.
from cone.
@jondgoodwin it doesnt work for me:
fn sum() i32 {
mut sum = 0
each i in 1 <= 5
sum += i
sum
}
fn main()
sum()
Error:
Error 1003: Expected semicolon - skipping forward to find it
--> each i in 1 <= 5
^--- work/test.cone:6:2
from cone.
Because once you turn it off, implicit white space is turned completely off for everything inside. At that point you must consistently use curly braces inside (e.g., on the each block). You must also terminate all statements with semicolon, as your example is asking for at the end of 'mut sum = 0'.
from cone.
@jondgoodwin I like that rationale, once it's turned off it's completely off, I'd almost go further and do that for the whole file. it'd make it completely unambiguous what's going on and in a way declares that the file is completely copy-paste-able.
from cone.
Ok, I've now tried Python for a while and I actually liked it a lot. It's much faster to type and work with when you dont have to write braces all day. Is it more dangerous? Yes, of course. But on the whole I think it's worth it and indentation problems dont appear as often as you'd think.
from cone.
Related Issues (20)
- Compiler reporting of time is sometimes obviously overestimated HOT 2
- Anonymous function output passed to print HOT 1
- Array declaration fails in global scope HOT 1
- Can't access global variable, as if not seen, but in fact it is seen HOT 2
- Doc for `extern` misses (curly braces) xor (colons) HOT 1
- Fails to print u32 HOT 4
- `typedef` fails HOT 6
- Add support for typed array size HOT 1
- Automatic cast of index when using each HOT 1
- Multidim array type compiles but not usable HOT 2
- Problem with multiple return values HOT 4
- Global arrays are not accessible if not initialized HOT 1
- Literals with underscores not recognized by print and returns HOT 3
- + operator called as a method in backticks does not work or is not implemented HOT 1
- Adding elements to a collection with <- doesn't work HOT 1
- Gist creation broken on the playground
- Grammar railroad diagram HOT 5
- SSL certificate on website invalid since Mar 15, 2022 HOT 2
- Unaccounted for line counting when tokenizing strings HOT 1
- Using C from Cone: calling fopen() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cone.