9
votes
Fortnightly Programming Q&A Thread
General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.
Don't forget to format your code using the triple backticks or tildes:
Here is my schema:
```sql
CREATE TABLE article_to_warehouse (
article_id INTEGER
, warehouse_id INTEGER
)
;
```
How do I add a `UNIQUE` constraint?
I am a self taught programmer, originally a physics major. I currently use Python, Java, and C/C++ all the time. I learned C and Java because I had to for a project. I learned Python (in the version 1.5 days), because it seemed cool at the time; that worked out pretty well. Not saying I'm a pundit, I was just lucky.
I would like to self-study and learn another language, just to learn new concepts, get better. I have some ideas, about which one, but I'd rather get other people's opinions.
In terms of learning new programming concepts I would suggest the following:
Haskell
Purely functional language. Java has been introducing functional concepts slowly (lambda functions, map, reduce, etc), but in Haskell you will be forced to do everything in the functional paradigm.
Learn you a Haskell for Great Good is a great starting point.
Lisp
I would suggest Scheme or Common Lisp. There is a reason lisp has influenced so many languages and to this day continues to be used. A few things to expect:
* hot code reloading and pretty great introspection capabilities with the runtime
* One of the best object system out there (CLOS)
* Macros which allows you to manipulate AST directly.
Practical Common Lisp and Land of Lisp are nice books to start learning common lisp.
I will also be remiss if I do not suggest SICP
Rust
Memory management using borrow-checker. Coming from C, this would be a great language to learn.
The Rust Programming language book is great and is what I used.
Erlang/Elixir
Concurrency with Actor model (You can try Akka in Java to get a taste).
Learn you Some Erlang for Great Good in the same vein as the Haskell book is nice.
Edit: You can also check Clojure, if you want to try out a lisp that runs in JVM. It is not CommonLisp, but is still a lisp [1].
There is also Hy for python
I was thinking of either Haskell or Lisp, in fact. I have toyed around with Rust a little, and it seems to me that it is likely to be useful and more popular. But, other than the borrow checker, it's just another procedural language.
Hy looks very interesting, thanks!
I forgot to include this in my initial post:
If you go down the road of learning CommonLisp and like learning from videos, Baggers has a set of videos on setting up your CommonLisp dev environment and starting development here (Emacs with slime or sly adds a lot of value when working with common-lisp)
He also has another set of videos (each avg about 5 mins long), and each one deals with a single topic in common-lisp
I would also like to add that Common Lisp has been around for a while, which means it does have a bit of historic cruft/baggage that comes along with it, which may put off new comers to the language!
We could start a whole new thread about learning styles... I'm not much of a fan of studying programming with videos. I learned how to fix the carburetor in my lawn mower from a video. It's perfect for that (and the guys who produce those videos are a hoot too). IMO, for programming, you need a book, a development system, examples, and problems to solve.
I'm a beginner at programming, but seasoned linux user (17 years at least, i'm 34yo today). I can output bash scripts for my needs easily.
I decided to finally learn some programming. I should have started earlier, but i didn't have any interest.
I decided to start with a more modern language and chose Go. I got an udemy course and learned it pretty well until i started messing with loops inside of multi dimensional arrays, parsing texts and replacing words. My head went spinning and i was just going along with the classes without understanding what i was doing at that point.
Corona came and i just stopped. I decided to come back this week and try Python because it is an easier language and i will have more use for it right now since i don't have big ideas. I just want to implement some automation in my desktop so instead of using bash i can try with Python and learn more about programming (and who knows, Python has several jobs so maybe i can freelance a little).
It's going well, but even if i'm not a programmer, coming from Go i think Python does a lot of things with just one command that i feel like i'm being fooled.
Don't know if i'm using the right word, but i feel like i'm programming with training wheels.
In Go, if i needed to mess inside an array i would loop and find something there. It was not easy for a beginner, but i could understand that it was going through things because i told it to do. In Python, it looks just like magic to me.
It's not a question per se, just a thought i am having while learning Python. I think Python is good and i'll keep learning, but i think i'll try Go again after that.
I like the error handling in Go too. Hope there is something similar in Python.
It sounds like this (free) book might be up your alley, it's specifically aimed at beginners that want to learn Python for uses like that: Automate the Boring Stuff with Python
This is a great book for picking up python!
The author also has a course on Udemy and is currently giving it away for free (I think for another day) with coupon code COPSHOTMEINPORTLAND2
(relevant reddit thread here)
(edit: mention @crdpa for notification)
Thanks! Just got it for free!
I just started using Go professionally, and that's a very real difference between the two languages. I'm writing more
for
loops than I have in many years. Go is a very manual language, especially compared to python.But, compared to something like C, Go also has training wheels! You don't have to worry about allocating and deallocating memory, there's a reasonable string implementation out of the box, and loads more. And compared to assembly, C is a cake walk!
I guess I mean to say that I hope you don't worry too much about whether or not you're using training wheels. There's lots to learn, and unless you have a specific need or passion, don't think that you're Doing It Wrong, or Taking The Easy Way Out. Learn what you need to scratch your own itch.
Go is by design a very small language which can be learnt fairly quickly (excluding channels and goroutines the language can be taught in a few hours) This may cause it to be more verbose, as in explicitly having to loop over an array, etc.
Python does also include imperative loops similar to go, however python also has functional constructs like list comprehensions, lambda functions, fold, map-reduce, etc which is what I believe you are referring to.
These are just functional concepts sprinkled in python :)
I think the Learn you A Haskell for Great Good! book does an excellent job at explaining these basic functional concepts, this books explains these in terms of Haskell but the core concepts remain the same if you are going to be applying them in python or Java or some other language that supports those constructs (this chapter deals with list comprehensions and this chapter that deals with folds and map-reduce)
Thanks! I'll check those resources.
Programming with a higher level language might be the term you're looking for. (and "higher" is meant to be taken as "further from the metal, transistor, memory pointers and all" instead of "better /more complex")
I am not sure if I would consider go a lower level language exactly, it is garbage collected and handles a lot of memory management (however understanding the underlying memory implications of your code is often needed when dealing with arrays/maps being passed around functions.)
I would say python offers a lot more abstractions to the programmer allowing for more expressive and/or terse code to be written.
Up until Java7 there were no lambda functions and streams in Java either, I would definitely not be calling Java7 a low level language ;)
However the relative meaning of higher level language does factor here I suppose [1]
Ah, you are probably right. In my kind I conflated "high level" with "have abstractions".
I've taken a little time to learn some Perl using Moderl Perl, 4th edition. Can you recommend some exercises, tasks, projects, that would be a fun way to apply the language? I didn't study CS and don't use any programming languages in my day-job, so I don't have much opportunity for practical application.
Project Euler: A huge set of problems you can work through in any programming language. This will also help you pick up CS concepts along the way! Great to get your feet wet in a new programming language.
There are also sites like leetcode which aggregate coding problems.
The above may not necessarily be fun, but would be helpful if you are trying to transition to a coding career.
If you like Koans, there is this for Perl.
A general advice I give to programmers who are learning a new language, is to solve a problem they have already done so in a language they already know, in their target language.
This doesn't work for the first language you learn! so I would suggest try to pick an inconvenience that you face in your day-to-day workflow and see if you can automate it or alleviate it. (This is similar to the premise of the (free) book Automate the Boring Stuff @Deimos suggested above, however that is for python).
If you deal with lot of reports at work, you could write a script that processes the data from those reports and displays what you want;
or a script that lets you keep track of things to do/fix around the house, etc
You could try building a webapp and host it locally so you and all your family members can post notes, like a digital whiteboard on the fridge, except it's on all your phones!
You could also try building a simple game! libraries like LÖVE and pyGame have made this much easier, I am not sure how feasible this suggestion would be for perl tho.
You should also check out the perl IRC channels and subreddit, they should be able to give you a lot more perl specific suggestions!
Off Topic: I haven't had to use Perl in over a decade, if you don't mind me asking, what made you want to learn Perl?
Thank you for so many suggestions!! I've also tried to learn a little bit of C++ through some free, online sites.
I decided to learn Perl for a few reasons. I got kind of frustrated trying to learn Python. I have experience in engineering software, where capitalization and formatting are pretty flexible, so having the tabbing be part of the syntax really bothered me. Another reason is that my workplace has quite a few Perl programs that are heavily used, so I thought it might be fun to pick up. Python would be a great choice if I was looking for work or did a project where my code would be used/viewed by someone else in the future, but I'm just learning additional languages for myself.
Programming at its core is just defining logic. The programming language is just semantics on how you define your logic :)
Perl is still a case-sensitive language, so be wary of that
I do understand the frustration with tabs in python, setting up your editor or IDE for the language you are coding in can definitely help a lot in terms of avoiding language-specific annoyances like this (even for Perl).
If you are using Perl scripts at work already, you could also fork them and add functionality to those that may make your life easier/better!
You get right to the root of the issue with the semantics of defining the logic. I really learn new skills best by reading textbooks, so finding Modern Perl available freely online was part of my decision. I also do really like the nature of the language. I know it's not used much now, but I suppose part of me just wants to go against the grain a little since this is just for my own fun.
But I was able to debug some Perl scripts on a system that refused to run them. It ended up being a trivial fix and voila. I emailed the maintainers of the script and they implemented my fix, which was hugely useful since I had tried (and failed) to write a bash script that mimicked the behavior.