|
Basically "hey it seems dumb that I need to specify the type of every variable" is correct, there are upsides to both approaches and even older vanguard languages have acknowledged that.
|
# ? Mar 17, 2022 21:09 |
|
|
# ? May 28, 2024 14:59 |
|
D34THROW posted:Ever have those moments when you look back at your old code, or how you used to do things, and have a look on your face? "The worst coder ever is me, 6 months ago."
|
# ? Mar 17, 2022 21:20 |
|
punk rebel ecks posted:I’ve just started learning Java and was wondering why I have to do things like put “int” in front of a number to state it’s a number rather than simply not putting quotes around it. Or why I need curly brackets everywhere. Languages like Haskell go one step further - functions usually don't even need type signatures because they can be inferred. You can write one though, and the compiler will make sure that it was able to deduce the same thing. So a lot of Java verbosity isn't strictly neccessary for a statically typed language. The below quicksort function takes a list of some type, and returns a list of the same type. If you tried to call it with anything else or treated the return value as something else you would get a compile-time error. Edit: The item type would have to be comparable since the function uses < and >= to compare items. If it wasn't doing that, then the item type could've been anything. code:
Deffon fucked around with this message at 21:35 on Mar 17, 2022 |
# ? Mar 17, 2022 21:29 |
|
I want to learn C++ once I have fully learned Python and Java. Would it be best to learn C first, before I learn C++?
|
# ? Mar 17, 2022 21:49 |
|
I would go for Python -> Java -> cython -> C++ if you still feel like it. If you aren't already using it, pick up mypy or one of the other static type checkers for python and start getting used to it before learning Java. For your actual question, C is different enough from C++ as to be actively harmful to your experience learning either after the other. The ++ is more of a generational leap thing than a simple increment.
|
# ? Mar 17, 2022 22:30 |
|
CarForumPoster posted:"The worst coder ever is me, 6 months ago." 1000x this. Past me is future me’s worst enemy. Learning to support future you is a huge step to enlightenment.
|
# ? Mar 18, 2022 00:30 |
|
punk rebel ecks posted:I want to learn C++ once I have fully learned Python and Java. Would it be best to learn C first, before I learn C++? No, you should just go straight to C++.The situations where you should use C are somewhat specific Under no circumstances should you go learn Java, not without a specific reason QuarkJets fucked around with this message at 03:58 on Mar 18, 2022 |
# ? Mar 18, 2022 03:56 |
|
QuarkJets posted:No, you should just go straight to C++.The situations where you should use C are somewhat specific I'm learning Java because I'm going to look for jobs with Python and like half the jobs I see says either knowledge of Java is a plus or even required.
|
# ? Mar 18, 2022 06:11 |
|
I found learning C pretty useful purely from an educational perspective. I’d never program anything outside of a classroom in it, but it makes you appreciate the abstractions a little bit more.
|
# ? Mar 18, 2022 06:17 |
|
C is a relatively small language and most of what you'd learn from it would transfer to C++ anyways, given that C is a subset of C++. Now, C++ proponents will rightly tell you that modern, best-practices C++ code is quite different from C, which is true, but if you're working in C++ in a professional capacity there's a drat good chance you're going to come across code bases that go back 30 years and include all flavors of C++ past and present, including straight C code that got shoved into a .cpp file at one point. You at least want to know what that stuff is doing. One of Java or C# is worth knowing because the vast majority of the world's software over the past 30 years is written in one of those languages and so it's good for employment purposes. They're easier language than C++ and some of the knowledge transfers too.
|
# ? Mar 18, 2022 15:43 |
|
punk rebel ecks posted:I want to learn C++ once I have fully learned Python and Java. Would it be best to learn C first, before I learn C++? Trying to take all language fanboy-ism out of it, the corporate world runs on Java (and Java-likes like C# and Go). Java and similar languages are a very powerful, flexible tool and you see them everywhere because they're an appropriate tool for a wide variety of solutions. Java itself feels old, lame, boring, occasionally frustrating, and verbose, but is also battle-proven for a whole host of situations that Python, PHP, NodeJS and others are not as good a fit for, or even not capable of reaching. Old companies, companies with enormous scale, or companies with high performance needs (games) will have a ton of C++ too. It will take more effort to do the same thing to the same level of safety and robust-ness in C++ than it will in Java/C#. That said, if you need memory efficiency and low latency, sometimes C++ is the tool for the job. It has so many sharp edges and hidden traps that some environments with low-latency needs will choose to write a really bizarre style of zero-allocation Java instead of doing C++. High-frequency trading famously does this, running Java with the GC off. There are a lot of languages competing to replace C++ with something safer, the biggest being Rust and the buzziest at this instant being Zig. Rust is seeing real adoption in places that have needed C++ in the past, like browsers. I'm not very experienced with Rust personally, but my understanding is that knowing C++ well is not necessarily useful for being effective in Rust. However, for all of the languages competing to be the next Java, I think that knowing Java well does help. I'm talking about Kotlin, and Scala, or even C#. I think that learning C is worth the effort. C itself is very small, and a separate language than modern C++. Also, when you do interop between languages, it will pretty much always be via C FFI, so if you're gluing together Rust and C++ code, you're probably doing it via C! Extending Python will always be via C FFI, same for Java JNI. So yes, that's a very long-winded way to say "I think that you should learn C first". Not because it helps you learn C++, but because C is the lingua franca that all of these tools can use to talk to each other at the point that you're gluing stuff together. And if you aren't heading somewhere that needs C++, there is a reason that Rust has a cult of people saying "use Rust all the time everywhere", Rust has less downsides than C++ in most situations.
|
# ? Mar 18, 2022 17:44 |
|
CarForumPoster posted:"The worst coder ever is me, 6 months ago." If you truly believe this you have not yet fully experienced the true hell that is other people's code. I'm never going to write an entire codebase full of chained cascading callbacks no matter how drunk/unmotivated I become. I'm also unlikely to ever write a function that will iterate through an entire db table deleting records if it's passed a null instead of a record ID*. * Deployed to production, no less. The issue was discovered after everyone woke up one morning wondering where all da data done gone. Their backup script had been silently failing for over a month because their storage was full and we ended up having to reconstruct their database by replaying changes against the last known good backup using the incredibly verbose log entries they were inexplicably emitting on every request.
|
# ? Mar 18, 2022 18:10 |
|
And another one of those -at-my-past-self moments. Instead of taking input from a Flask form and putting it into an object, then passing the new object's attributes individually to a calculation function...why not just pass the object itself? That way I'm not passing n parameters, I'm just passing one.Python code:
Python code:
Metasyntactic variables are fun
|
# ? Mar 18, 2022 18:32 |
Actually that reminds me of a problem I'm trying to figure out an elegant way around in Django. I'll go post in the Django thread though
|
|
# ? Mar 18, 2022 18:46 |
|
Twerk from Home posted:Trying to take all language fanboy-ism out of it, the corporate world runs on Java (and Java-likes like C# and Go). Java and similar languages are a very powerful, flexible tool and you see them everywhere because they're an appropriate tool for a wide variety of solutions. Java itself feels old, lame, boring, occasionally frustrating, and verbose, but is also battle-proven for a whole host of situations that Python, PHP, NodeJS and others are not as good a fit for, or even not capable of reaching. Great post. Maybe I’ll learn Rust instead of C++. Are there any games made in Rust?
|
# ? Mar 18, 2022 18:49 |
|
punk rebel ecks posted:Are there any games made in Rust?
|
# ? Mar 18, 2022 19:20 |
|
In JupyterLab how would I change the terminal from Windows Powershell to the anaconda prompt? Been searching for a while and I thought conda init might be what does it, but that does not seem to work.
|
# ? Mar 18, 2022 19:43 |
|
Jose Cuervo posted:In JupyterLab how would I change the terminal from Windows Powershell to the anaconda prompt? Been searching for a while and I thought I use Jupyter Notebook but the general way you get to the "Anaconda" terminal from command prompt is by running activate (activate.bat on windows). This isn't a Jupyter Lab specific answer though. I have a batch file that runs a jupyter notebook on a schedule this way. Explained a bit more: https://stackoverflow.com/questions/46305569/how-to-make-batch-files-run-in-anaconda-prompt
|
# ? Mar 18, 2022 19:48 |
|
CarForumPoster posted:I use Jupyter Notebook but the general way you get to the "Anaconda" terminal from command prompt is by running activate (activate.bat on windows). This isn't a Jupyter Lab specific answer though. I have a batch file that runs a jupyter notebook on a schedule this way. Got it, thanks.
|
# ? Mar 19, 2022 00:26 |
|
I've said before that I think Python is a bad language, or at least one where its designers have consistently made poor design decisions, to the point where there's a FAQ about them. But here is a specific, and interesting example: Today I learned about the walrus operator. Or rather, I finally updated a machine to a recent enough version of Python to be able to make use of it. Read the PEP, it's well motivated, and a good change for the language. But assignment expressions is something that's existed in other languages (Ruby, C, etc.) for decades--why did it take so long for Python folks to come around on it? Well, look at an older version of the aforementioned FAQ: The aforementioned FAQ posted:Why can’t I use an assignment in an expression? By the way, the walrus operator version of the above code is: Python code:
ExcessBLarg! fucked around with this message at 03:15 on Mar 20, 2022 |
# ? Mar 20, 2022 03:08 |
|
ExcessBLarg! posted:I've said before that I think Python is a bad language, or at least one where its designers have consistently made poor design decisions, to the point where there's a FAQ about them. But here is a specific, and interesting example: Okay
|
# ? Mar 20, 2022 03:53 |
|
ExcessBLarg! posted:I've said before that I think Python is a bad language, or at least one where its designers have consistently made poor design decisions, to the point where there's a FAQ about them. But here is a specific, and interesting example: Sounds like you're ready for Go.
|
# ? Mar 20, 2022 13:23 |
|
All languages are bad, if you don’t hate the design of your favorite, you haven’t used it enough. My most recent about python is that docstrings are statements.
|
# ? Mar 20, 2022 15:59 |
|
Mmm that sounds like something a Stockholmed Pythonist would say.
|
# ? Mar 20, 2022 16:15 |
|
Electoral Surgery posted:All languages are bad, if you don’t hate the design of your favorite, you haven’t used it enough. What, that you can get to the docstring with foo.__doc__? EDIT: Mods plz change title to Stockholmed Pythonists tia
|
# ? Mar 20, 2022 18:52 |
|
Electoral Surgery posted:My most recent about python is that docstrings are statements. Could you clarify what you mean?
|
# ? Mar 20, 2022 18:59 |
|
To speak for Electoral Surgery, I think the idea is that it's a little weird that docstrings are string literals rather than a type of comment. In my experience it gives people the idea they can use triple-quoted string literals throughout their code as multiline comments. I've had to explain that distinction to more than a few less experienced Python developers. (edit: wrong poster named) SurgicalOntologist fucked around with this message at 22:20 on Mar 20, 2022 |
# ? Mar 20, 2022 20:23 |
|
QuarkJets posted:Could you clarify what you mean? Until a few days ago, my mental model for docstrings was "a special kind of comment, there are some tools to generate documentation from them, whatever". But they're not comments (ignored by the interpreter), they're statements with no effect or side effect. This in syntactically valid code: code:
I found out about this when we turned on an analysis tool that happened to complain about unnecessary pass statements.
|
# ? Mar 20, 2022 20:46 |
|
you can use triple quoted strings as multi line comments, just don't have them also be docstrings. iirc the parser ignores them unless they are the first line in a class or module
|
# ? Mar 20, 2022 20:48 |
|
Electoral Surgery posted:Until a few days ago, my mental model for docstrings was "a special kind of comment, there are some tools to generate documentation from them, whatever". But they're not comments (ignored by the interpreter), they're statements with no effect or side effect. So the problem is that people think that triple-quoted strings are comments? People should probably be disabused of that notion So for instance this should also work, because a valid statement exists inside the class: code:
|
# ? Mar 20, 2022 21:01 |
|
12 rats tied together posted:you can use triple quoted strings as multi line comments, just don't have them also be docstrings. iirc the parser ignores them unless they are the first line in a class or module Maybe it ignroes all string literals that aren't assigned to a variable, but it doesn't ignore all triple-quoted strings. I use them all the time for multiline strings.
|
# ? Mar 20, 2022 22:21 |
|
code:
|
# ? Mar 21, 2022 14:03 |
|
12 rats tied together posted:you can use triple quoted strings as multi line comments, just don't have them also be docstrings. iirc the parser ignores them unless they are the first line in a class or module Or, you know, don't. I just indent lines after the first . Pycharm even recognizes it as a continuation if you do it for tagged comments (TODO and poo poo). Python code:
|
# ? Mar 21, 2022 15:50 |
|
Asking this in the Python thread because it's the language I'm most familiar with, but open to other suggestions: Is anyone aware of a tool or library that will scrape all of the replies to an individual tweet? I've been using snscrape to scrape tweets containing keywords, but I also have an instance where I need to scrape all of the replies to a specific tweet, which snscrape can't do.
|
# ? Mar 22, 2022 04:36 |
|
So I'm trying to have `self.button_lights` change it's Pixmap image while this codes runs so it can simulate a "loading light that blinks". But no matter what I do, the it doesn't change until the function is finished.code:
Messing around with it, even if I take the code out of QTimer and just have the image only change once it still doesn't run until the end of the code when everything else is finished.
|
# ? Mar 22, 2022 04:45 |
|
Tuxedo Gin posted:Asking this in the Python thread because it's the language I'm most familiar with, but open to other suggestions: I don't think the twitter API itself has an endpoint for replies to a specific tweet. I think the only way around it is to scrape all tweets that mention @user and throw away the ones that aren't replies to a given tweet.
|
# ? Mar 22, 2022 05:06 |
|
punk rebel ecks posted:So I'm trying to have `self.button_lights` change it's Pixmap image while this codes runs so it can simulate a "loading light that blinks". But no matter what I do, the it doesn't change until the function is finished. There's a lot of extraneous stuff going on here and I don't really understand what you want to do, sorry. Here's a simple example that flips a QLabel between two images, is that kind of what you're looking for? Python code:
QTimer will emit a signal every 1000 ms in this implementation, and that signal is connected to the changeImage method, which just flips the label between 1 of 2 preloaded pixmaps. So every 1000 ms the label contents change to the other preloaded image, which I just hard-coded as a tuple that the class owns. This was just something that I mocked up real quick in Notepad++, I probably could have used a fancier collection and iterators and the formatting is probably horrible but I hope this helps QuarkJets fucked around with this message at 06:40 on Mar 22, 2022 |
# ? Mar 22, 2022 06:36 |
|
fisting by many posted:I don't think the twitter API itself has an endpoint for replies to a specific tweet. I think the only way around it is to scrape all tweets that mention @user and throw away the ones that aren't replies to a given tweet. I assume maybe the paid products can query on that, cause why wouldn't they?
|
# ? Mar 22, 2022 18:12 |
|
So I have a bit of a best practices question. In the event that you have a function that mutates a data structure like a list/etc, is it best practice to return the mutated version, or to just make it clear in the docstring that the function mutates the object? For the sake of argument, let's assume that this isn't a library or other externally facing function and is pretty tightly bound business logic specific to a situation, where you're separating code out into functions to improve readability/etc.code:
code:
|
# ? Mar 22, 2022 20:05 |
|
|
# ? May 28, 2024 14:59 |
|
I think that's kind of up to your preference. Though if you are not returning anything then you should be very clear that the function does not return anything and thus mutates an argument as a side effect. It shouldn't do both; either return a new object or mutate the existing one.
|
# ? Mar 22, 2022 20:09 |