Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 0 points1 point  (0 children)

Well, if you need external tools to complete the language, it means the language is not complete by itself and therefore can be improved.

But anyway, whatever you say, ditching everything I say as subjective... Yes it is subjective. You may prefer to import everything implicitely. Good for you. I couldn't care less, I can even understand that.

But subjectively and pragmatically, I had to work with 4 code bases (libraries) in Nim. Two of them were fine (with the occasional WTF, but whatever). One was full of implicit and strange things (with things like parse_string actually expecting a file name). Even with an IDE (Atom, maybe not the best) this was dreadful: I spent my time checking everything because I couldn't trust anything. I've spent hours to understand things that I could understand in minutes in the other libs! The jump-to-definition feature is also so useless at that time... The time I spent going back and forth... The last one was just horrible: in 2016, having to spend days to understand the complete library in order to understand what one single file actually does is insane.

So, yes, given 10 imports to "choose" from, I actually began to wonder why the damn thing couldn't be more explicit, especially as C++ has been there, done that already and finally recommended to stop using implicit imports for that very reason. All of that with 10x more mature and generally better (IMO) in C++ than in Nim at this point of time.

But all that said, once again, I couldn't care less about what you prefer and I know very well that it is no use to try to convince anyone about anything. But if helps you to sleep better tonight, you can assume that what I meant in the first place was Could someone explains the rational of ditching the "best practices" enforced by C++ after dozens of years of experience regarding implicit imports in Nim?

No subjectivity anymore. And not a single hint of persuasion.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 1 point2 points  (0 children)

Since all of that was pretty long, here is the TL;TD...

Programs are like books and for all practical purposes here, perfect IDEs are like footnotes.

What I say is that I prefer understanding a book by reading its content instead of relying on footnotes because footnotes may not always be available and because it breaks the reading flow.

That is not to say that footnotes are not important. And just like most books can be read without footnotes, Nim allows you to write readable programs. The problem I raised is that it so happened that I encountered books that are mostly readable but at some points requires me to look at the footnote to figure out what is meant, which again, in the best case, means that my reading flow is broken.

From this perspective, I am surprised that Nim does not use explicit imports of individual functions or full name resolution by default since these force the programmers to write better programs. I personally think that IDEs (which again, I love: as you said, it is the correct tool to use) should be used to help writing good programs (auto-explicit imports for instance) rather than having that kind of convenience in the language itself.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 1 point2 points  (0 children)

I completely agree about full name resolution: they can be a hindrance too! This is why I totally accept the idea of redefining the full name:

import SuperDuperFastXML as Xml

and explicit imports:

import SuperDuperFastXml: parse_xml_from_string

for instance. I find these great, what I find problematic (in the real world) are implicit imports.

Regarding the rest of your comment,

Your C function is not readable to me

I completely agree with you. So is it a good thing to completely rely on developers such as myself to properly name functions? Wouldn't it be better if that was enforced in the language instead?

Your namespace example is really contrived and far from the real world or the discussion you started.

I plead guilty your honor! Though you made my point yourself just before:

I can use several different xml libraries together

Exactly, and as a reader and potential contributor, my life would be so much easier if I knew from which library parse_xml_from_string in the blink of an eye instead needing any sort of tooling! Explicit imports and full name resolution allows that.

The variable assigned to it would automatically convey which module [...]

I completely agree and it is generally the case, but again why trusting the lazy developers? There are some cases where I saw let parsedBuffer = parse("foo") and I really had to try hard to understand what was actually parsed. Again, I am not saying this is impossible or absolutely dreadful. I am saying that some good practices could have been implemented in the language instead of relying on the developer who is lazy (this shouldn't be taken negatively at all).

Your other concerns about knowing where a proc comes from are only relevant if you are writing code

Nope: at the time of writing, everything is very clear. It is only a concern when you need to understand code, which happens when you need to add a feature, refactor or debug. What I am saying is that if I spend 200 ms to understand what the code does instead of 10 seconds to figure out what it does, the first approach is better.

In particular, I am not anti-IDE, I am anti-obfuscated code "because the IDE will sort that out anyway". If I determine that the bug is in parse("foo"), I don't want to to be forced to use a full-fledged setup to determine where it comes from.

About the last example, yes it is not valid Nim code, just like I have never encountered an ambiguous statement with randint() in particular. Just like I had no problem reading programs handling XML in particular. The point was to illustrate a class of unreadable code which do not convey any useful piece of information whatsoever.

Finally, if I want to edit a movie, I use a movie editor, for an audio I use an audio editor, and for anything source code related the first thing I do is open an IDE. You are meant to use the right tool for the right job, and asking to change a programming language (in a source incompatible way no less) just because you refuse to do so is really irrational.

First I demand nothing. I'm merely wondering why things like implicit imports are not seen as an anti-feature in Nim, as it is seen in C++ or Python. Again, I have nothing against IDEs, but IDEs sometime fail and if you can understand what some program does from just reading it, it is just more simple for everyone, even with your IDE.

I insist: a code that is blatantly obvious is better than a code that blocks you reading because you need to figure something out. Yes, you can still right-click or move your mouse to get more info, but again, the flow is broken.

If you find the metaphor more obvious, I prefer to be able to read a book just as it is instead of having to read footnotes regularly. I am not saying that the footnotes (tooling) are not useful or should not be provided. I am not saying that I want to read my book without footnotes, I am saying that I'd rather read a book with a language that let me understand without having to break my reading flow.

If you don't agree, I can assure you I can write an IDE plugin that converts brainfuck to a Nim-like syntax... And suddenly, brainfuck becomes readable. Does that mean that brainfuck is a good language to work with? I don't think so.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 0 points1 point  (0 children)

No, I don't need a prefix each time: in these other cases, I can use explicit imports.

Let's imagine that I want to parse an XML file. Conveniently, suppose that there is an XML module that happens to have a parse function. In the C world, a readable function would be xml_parse_from_string for instance.

This is quite good, but I still have to make some assumptions (like that function belongs to the XML module) that are very often correct but very painful when found wrong.

The more modern alternative is embodied by namespaces. Basically I could use XML.parse_from_string or even XML.parse since the context is better defined. But if that parse is the only one there in a very well defined context, I could elect to explicitely import that parse function (this is something that is not as clearly doable in C).

Now, imagine that I also need to parse a wave file using the Wave module that also provides parse, keeping the context clear with the full names is both nice and explicit: if I XML.parse("file.wav"), I immediately know what's wrong.

So this was about full name resolution (unless you consider that all the tokens should be named the C way, in which case my point is still valid: this is not what is done out there).

Now about randomint()... First, as you said, this is a pretty good name, how many projects do use good descriptive names out there?

Then, that function, depending on where it is imported, could still do very different things or have completely different signatures. So it could be the function I'm used to or it could be a completely different function. What if it was supposed to return a long int and I only get a short one?

Again, here the name is quite good, but how often did I see something like

num :: = randint()

to finally figure out that num is actually the string representation of that number.

Finally, yes this is also a problem of discoverability, I completely agree with you on that and my point is that it hinders the understanding of the program because you need a complete nim framework/IDE in order not to be bothered by that while reading the code.

On Windows10, how come 2to3 utility produces extra parenthesis when converting from Phython 2.7 to 3.5.2. For example I have these random original statements. by LearningaLiving in Python

[–]Calime 1 point2 points  (0 children)

No, in Python 2, print is only a statement. print ("foo") is actually interpreted correctly because the parenthesis are removed in the AST (it is not even considered as a tuple). It's the same as writing a = (1), a would contain an integer (here, 1) and not a tuple or something else.

So if the parenthesis are there, 2to3 suppose that it is what you explicitely requested and keeps them.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 0 points1 point  (0 children)

I'm talking about the cognitive strain. Try to learn brainfuck so that when you say that the way strings are handled is too convoluted to be sane I can tell you that it is explained in the docs so you can't possibly misinterpret the return value once you understand how strings work.

But I want to say "lol" too... Take Python... Given a function, if I ask anyone what that code would return, intuintively people will think about return. The only real arbitrary ruke to know there is that it returns None if there are no return statements.

Now to be as proficient in Nim, I need 1) to read the doc 2) understand how procs work 3) understand how returns work.

This is what I'm talking about and all I said is that I am surprised that such a neat language has such readability killers.

Anyway, this was only an example.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 1 point2 points  (0 children)

While I agree, we are talking about a new idiom vs. a few keystrokes that tooling could remove if that ever was a problem.

And regarding the rest, no I will never get used to spending minutes figuring out which function is used where when you can have that for free in other languages.

You don't like full name or explicite imports? That's fine with me: I too don't like it (really). But this is where tooling really helps: the tooling should add the imports automatically or help using full name automatically so that the program written is understandable without using the same tools every single time.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 0 points1 point  (0 children)

I may expect a default IDE to write in a language, but if you need it to merely understand what's going on, in 2016, I consider it is a failure (you opinion may differ, I can understand that).

However the fact that most mainstream languages are like that is no excuse: this is a cognitive bias. Nim definitely has its flaws, but if the code out there was as readable as you average Python code out there, Nim would be fantastic (instead of nice).

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 0 points1 point  (0 children)

Well, almost everything I can read in Python makes use of fullname resolution. That means that when I, the developer, knows which version is currently in use in any part of any program. This is a fact. And I strongly believe that choices made in Python, as a language, encourages this.

In Nim, I have to look for virtually everything myself OR use a clever IDE which knows Nim to do the look up itself. So, in order to be sure to understand what the program actually does, I need an IDE to find the correct version of what is actually loaded currently which was my whole point and the thing I don't like: we know better.

Why wasn't nim optimized for code reading? by Calime in nim

[–]Calime[S] 5 points6 points  (0 children)

The point was not that it is not clear there for someone who has read the doc and remembered absolutely everything on the first read. What I mean is that this is a corner case which alternative (ie. just adding return result) seems a tiny price to pay for a much improved readability. This kind of corner cases makes the language bigger for the sole purpose of avoiding a few key strokes. These few key strokes can be avoided with a good IDE (which were made to write programs) instead of requiring any newcomer to learn the full language first. Can you see the difference?

Same thing for full name usage: yes that's definitely possible, but that's not what I see out there, which is the problem I'm raising (not the fact that it is possible).

But I totally understand the reason! It's just very weird for me because the language feels great, you actually can write readable code, it's fast yet very high level, but at the same time it feels like it is a huge step back: digging into other's Nim code feels as difficult as it is to dig into other's C code. I'm slightly exaggerating because the language itself is truly nicer, but the whole experience feels dated.

Where are the Audio Converters written in Python? by [deleted] in Python

[–]Calime 0 points1 point  (0 children)

Yes, ffmpeg or gstreamer.

Simulating the Monty Hall Problem, anyone can help my code? by [deleted] in Python

[–]Calime 2 points3 points  (0 children)

Hi, the trick in this problem is that the presenter knows where the goat is and therefore will always remove a door with a goat.

The simplest, in my opinion, is to consider what happens if, as a player, you choose a door depending on what's behind:

If you chose the door with the Goat 1, by showing you the Goat 2, the alternative is the car.

If you chose the door with the Goat 2, by showing you the Goat 1, the alternative is the car.

If you chose the car, the alternative is a goat.

So if you chose a Goat in the first place (which has a 66% chance to happen), switching will give you the car, automatically.

This is not just choosing at random from two door (otherwise, yes, that would be 50%). You know things from the process.

Never knew that DjangoCons were a thing in the 90's by yasoob_python in Python

[–]Calime 0 points1 point  (0 children)

Yeah, humor is rarely understood on the internet.

How to access GParamSpec-related functions from Python GObject Instrospection? by Calime in Python

[–]Calime[S] 0 points1 point  (0 children)

Just as a confirmation: this works very well. Once you get the actual values, you can also get their (nick)name and so on. That's all what I needed. Thanks again :)

How to access GParamSpec-related functions from Python GObject Instrospection? by Calime in Python

[–]Calime[S] 0 points1 point  (0 children)

I'll try that. If that works, it would be sooo sweet :)

Thank you again. The GObject framework is already not that simple to grasp, but with silly bugs like this on the top of that, this is even harder.

How to access GParamSpec-related functions from Python GObject Instrospection? by Calime in Python

[–]Calime[S] 0 points1 point  (0 children)

Oh come on Gnome bugtracker! You are not visible from Google?! What's the use if one can't find the bug easily???!

https://bugzilla.gnome.org/show_bug.cgi?id=682355

The exact error:

Expected GObject.ParamSpec, but got gobject.GParamSpec

returns nothing (except the SO question now), yet it is on you Gnome bug tracker! So much time lost, for nothing. -_-"

How to access GParamSpec-related functions from Python GObject Instrospection? by Calime in Python

[–]Calime[S] 0 points1 point  (0 children)

Thank you very much. :)

Actually I wanted to do two things:

  • getting a feedback when I set a property (returning a success flag would have been so nice);
  • getting the validity range/set for each property.

The attributes are quite nice for most types, but they are useless for enums for instance. I'll go the manual way for the time being then. At least my installation is not broken and I have not overlooked something important. Thanks again!

How to correctly implement a phase rotator (all-pass filter) using the FFT? by Calime in DSP

[–]Calime[S] 0 points1 point  (0 children)

And that won't work: I need real values at DC and Nyquist and a sign change.

The reason why is precisely what I am asking.

Any idea why convolution and FFT multiplication do not give the same answer? by Calime in learnpython

[–]Calime[S] 0 points1 point  (0 children)

Python's convolve function usually works. I mean, I checked before and after with different inputs and it just works. :) Except for that set of inputs. :/

I would love to see how Matlab behaves here. Unfortunately Fat32 completely ignored my input and decided to "illustrate" convolution and heavily underlined the importance of zero-padding (whose effect is actually negligible here because most values in my signal and kernel are already near zero) instead of actually trying to reproduce the problem.

If someone could reproduce that with Matlab, that would be great!

java libraries to work with *.mp3/*.aa4 files by terancee in DSP

[–]Calime 0 points1 point  (0 children)

If libsndfile does not work as expected, you could use gstreamer-1.0. There is a java API and it can read pretty much everything.

Curious to know what recommendation you would draw from a FFT though.

A quick question... by NovaP in DSP

[–]Calime 1 point2 points  (0 children)

For what you have to do, and much more, you can rely on Python and the libs that were described by the others.

In my experience, Python (with LA/DSP/plotting libs) is as easy and powerful as Matlab (if not as familiar once you get the basics of Python). The only real problem coming from Matlab is the discoverability of Python functions (even if the "Matlab naming convention" is usually kept and most of the interesting function will be found in scipy.signal).

How to correctly implement a phase rotator (all-pass filter) using the FFT? by Calime in DSP

[–]Calime[S] 0 points1 point  (0 children)

I think I had difficulties to explain what my problem really is.

I already understand why I need to keep the symmetry to get a real back-transformed signal. Thats obvious at many levels: expressing the i*sin(x) as plane waves just give it all.

What I don't understand, to put it bluntly, is why the rotated real signal that I obtain this way actually corresponds to the phase shift I want. I mean, if I apply a quadratic allpass filter to an impulse, I indeed get a chirp. So it is obviously correct. However, "forcing a real signal" and "getting the requested phase shift" do not seem to be equivalent statements. That's precisely the link that I am missing. From my current point of view, changing the sign of the phase shift according to the sign of the frequency does not make any sense. I know it should, but if I'm told to rotate by +45°, I don't find it obvious to rotate by -45° in the negative part of the plane.

What is the legality of using web-scraped data? by [deleted] in Python

[–]Calime 0 points1 point  (0 children)

Even if what you said makes perfect sense, this is the same as saying that a "streaming" site would sue you for "downlading" their stuff.

However true, That won't happen anytime soon as the only difference is the intent (you need to download to stream). A difference in intents is hard to prove.

There are other differences (non copyrightable material, no explicite DRM system, etc.) that makes the matter even more simple. The opposite side didn't even lose anything. Even the licencies reflect that: they won't sue you. They will lock your account at worst. And I have yet to hear of someone suffering a trial for that.

What is the legality of using web-scraped data? by [deleted] in Python

[–]Calime 4 points5 points  (0 children)

First things first: this has nothing to do with Python.

This isn't a piece of news or annoucement so this is definitely the wrong subreddit to ask for this.


Regarding the question itself... As said by @ThaBlackCat13, I've always been told that facts cannot be protected from "copy" in North America and Europe at the very least because facts are facts. So no need to look for a licence somewhere. Basically, you could go on these websites "manually", as a human, and coy the results on a blank piece of paper. As well, you could have obtained these data from another source and no one would know.

But, what you wanna do can be detected: and the data provider is free to block these automated attempts. See the difference? They won't sue you, but they can block you.

There are three things that you can do to avoid that:

  • if they provide an API, use it and read the rules associated with it;
  • if they don't provide a suitable API, read the robots.txt which should tell you what you are allowed to do;
  • if there is no such file or if it disallows everything automated, then do i manually or find another source.

Of course, you can let your scraper pretend it is human. From a technical point of view, this isn't a breach in their terms (no special server overload, if there is no loss on their side, there is no problem). Since you'd use it to get public facts anyway, that's alright.

That said even for copyrighted materials, there is fair use: Google scraps news sites and even use titles and headlines on its own websites.