559 karma · joined Aug 26, 2016 (10y ago) · 276 submissions
comment 9y ago · link · parent
Only if the programmer chooses to not handle exceptions, which is bad practice.
>and will die just the same as the hard unwrapped Rust version with the only benefit it actually produces a more user-friendly error and it doesn't look as ugly.
No, it won't die unless the programmer wants it to. In Python you can catch an exception and continue the operation in a different manner. In fact, it is common practice in a lot of Python libraries to use exceptions to determine the presence of data and act according to whether or not the exception occurred. If I'm not mistaken, I believe that this is common practice in most languages that utilize the exception pattern.
> I can't edit my reply anymore but the question was actually meant to be rhetorical rather than I really wanted an answer.
Well, you seem to not know a lot about exception handling in Python, so I hope I was at least a little helpful.
comment 9y ago · link · parent
Here are some links you may find useful if you decide to try again:
Documentation index: https://nim-lang.org/docs/theindex.html (everything)
Official Tutorial: https://nim-lang.org/docs/tut1.html
Standard library documentation: https://nim-lang.org/docs/lib.html
Language Manual: https://nim-lang.org/docs/manual.html (information on syntax, type system, GC, etc.)
Compiler user guide: https://nim-lang.org/docs/nimc.html
Backend docs: https://nim-lang.org/docs/backends.html (nim cmpiles to C, C++ and js)
Built in templating docs: https://nim-lang.org/docs/filters.html
How to tune the GC: https://nim-lang.org/docs/gc.html
Development tools docs: https://nim-lang.org/docs/tools.html
More about the compiler: https://nim-lang.org/docs/intern.html
All of these links come from nim-lang.org's documentation page here: https://nim-lang.org/documentation.html
comment 9y ago · link · parent
All of Python's exceptions are an instance of `Exception`. In order to catch and handle any exception that can be raised, you can use a `try, except` block with the base `Exception` class. This, however, is bad practice as there may be some exceptions you want to ignore and, generally, you also want to print a different error message depending on which exception was raised.
comment 9y ago · link · parent
I find it to be extremely simple to work with. It also does a fantastic job generating efficient queries due to the way it forces you to structure your models. The `F`, `Q`, and aggregation functions are top-notch as well. If none of the ORM features suit you for a particular query, Django ORM allows you to write the raw query yourself in a secure manner. Couple this with the Migration system, and I doubt you'll find a better ORM suite anywhere else.
I find Python has some of the best ORMs out there between Django ORM, SQLAlchemy, Peewee, and Pony.
comment 9y ago · link · parent
While I really enjoy the concept of Natural Keys, I just see so few places where they are applicable. If I was designing a banking Db schema, I could see using an account number as a primary key as long as I am not exposing my Db to anything but internal systems. However, if I'm designing a social networking platform, what can I use as a natural primary key for a user object? I can't use a name because not all names are unique and they can change. I can't use an email because they can change and I feel like Email addresses can get pretty large(more space and slower lookups). I could maybe use a username if I enforce that a username can never change and must be unique. But, we then run into the same issues as emails where a username can be fairly long and thus cause slower lookups. I also don't like the idea of using strings as primary keys either because I would need to take into account implementation details like string encoding (utf8, utf16, utf32, ascii, latin-1) and make sure to encode/decode on every lookup/insert.
So, I can see some use cases where natural primary keys make sense. However, I believe that for most use cases, artificial keys are a better choice. Integers don't take up a lot of space, it's easy to enforce uniqueness, they are a natural sequence, and they rarely, if ever need to change[1].
[1] In fact, I would make the argument that if you're altering primary keys at all, you're doing something wrong.
comment 9y ago · link · parent
Really? I've been working as a web programmer for about 5 years now. I use the term Web Programmer because I feel like the term Web Developer carries with it the connotation that you only work with Javascript.
My specialty is definitely with Python and more specifically with Django. Django's ORM is the first ORM I ever used. Maybe it's because I self taught, but I never had the inclination that FKs were an impediment to rapid iteration. In fact, quite the opposite. FKs are a fantastic way to enforce relationship constraints between tables/objects/models/whatever you want to call them.
Whenever I start on a new project, the first thing I do is start defining my data structure. In Django, this mostly involves using the ORM layer to define Model Classes. I usually define the core sets of models necessary for the application. As an example, if I were building a simple blog, I'd start by overriding Django's built in user model so I have the flexibility to add columns or place constraints on existing columns. Then I would define the post model which includes an `author` and a `category` FK column. Then I would define the `Category` model. I generate a migration script and run it. Every time I need to make a change to the Schema, I simply add or change whatever I need to and generate a new migration script alongside the old one. These migrations are dependent upon previous migrations and have version numbers. If I need to, I can roll back to a previous schema. Django makes this all very simple and actually separates the migrations out by which app the model definitions reside in. This means that I can make changes to multiple model definitions and only apply the changes to the Db for one of those model classes. It's very flexible.
So, after my long-winded explanation above, I don't see how people could find FKs to be restrictive when there are so many tools like Django's ORM and migration system that makes altering your schema so simple.
comment 9y ago · link · parent
My criticisms are just me simply voicing my frustration with, what seems to me, to be the generally accepted "best practice" for composing Redux applications.
Let me give you some short background: I've being doing backend work for years. Last year I signed on with a new project where I was in charge of both front and back-end work. Because of this, I was introduced to the modern front-end ecosystem and all of its intricacies. We've come a long way from jQuery. After evaluating many different front end libraries against project requirements it came down to using either Vue or React. We chose React because of its wider adoption. Eventually we hired on 2 front-end developers so I could focus on the server side of things. Well, here comes the project deadline and I'm having to pick up slack on the front-end. Now, since the new front-end devs re-wrote the entire front-end, I am struggling to understand why they structured it the way they did. They insist that having huge containers passing state down through multiple dumb components is the best way to structure the application. I feel like it introduces unnecessary complexity. Because our front-end devs have more experience in front-end development(obviously), I need to trust their judgment. I hope that helps you understand my frustrations.
>You _can_ even directly import the store into your component files and reference it directly, although that's discouraged for several reasons (per the Redux FAQ at http://redux.js.org/docs/faq/StoreSetup.html#store-setup-mul.... ).
Yes, I definitely want to steer clear of this pattern.
>Third, you shouldn't need to "propagate an event through 5 different callbacks". One of the main points of Redux is that you can `connect()` _any_ component to give it access to the store. If a deeply nested component needs to extract a couple values from the store, or dispatch an action, go ahead and connect it - you don't have limit yourself to only a couple connected components higher up in the tree (per http://redux.js.org/docs/faq/ReactRedux.html#react-multiple-.... ).
I should show this to my team. Maybe a Redux maintainer will do a better job convincing them than I will.
>I keep a big list of links to high-quality tutorials and articles on React, Redux, and related topics, at https://github.com/markerikson/react-redux-links . Specifically intended to be a great starting point for anyone trying to learn the ecosystem, as well as a solid source of good info on more advanced topics.
Thank you for this.
comment 9y ago · link · parent
I realize that the way my team is doing things is not the only way. It's difficult to change the minds of people who are already set in their ways even when you're in charge. My team believes that the method which I described above is the "best practice" way of composing with react. I disagree, but I need to work with what my team is comfortable with.
comment 9y ago · link · parent
Regarding you statement about abstraction layers, separation of concerns, and re-usability:
If I want a generic and re-usable component I just won't give it any data state. It may have local presentation state, but all data will be passed to it from a parent. Any operations the component allows will simply emit events. Both Vue and React are equally suitable for this and I have no complaints about either for generic components.
I'm not sure how being able to read central state in any component violates separation of concerns, however. The store is still handing all mutations to application state in Redux or Vuex. The difference with Vuex is that You do not need to have a chain of callbacks for dispatching actions, you do not need "connected containers", and you do not need to pass state through components in a tree that do not require that state. For instance, say I have a user profile page. This page displays user information received from a REST detail endpoint. Simple enough, right? I just have a `UserProfileContainer` where I define functions for fetching the user object from the API and then getters for retrieving that state. Now, I decide that I want to display a user's recent activities in a feed on the same page. Do I add to my `UserProfileContainer` to pass state down to the new feed component and it's children, or do I define the feed component as a new container? Or, do I define an intermediary `UserProfileLayout` component that is not a container and handles delegating state passed to it from the `UserProfileContainer`? If I do that I am passing application state through a component that has no use for it and I have to define an addional callback to propagate the event back to `UserProfileContainer`. Or maybe I should use `UserProfileContainer` itself to delegate state to the `UserInfo` and `UserFeed` components? How you compose this theoretical interface is probably defined by the structure of the rest of the application. I'm simply stating the Redux becomes more and more difficult to work with as the depth of component nesting increases.
comment 9y ago · link · parent
Vue really got it right using the prototype extension model for plugins.
I use React+Redux at my day job and I have to say that it is an absolute pain in the ass to do state management with Redux vs Vuex. Redux forces you to split all of your logic out into separate tiny little functions and constants. It even encourages you to split this all out into separate files.
Between the api functions, actions, reducers, connectors, routers, it all gets very complex very quickly. The worst part is using `react-redux` and creating connectors where I have to explicitly pass whatever actions and state I want to use explicitly to a container where I need to propagate that state to a component that's nested five levels deep. Then, if that component needs to dispatch an action I have to propagate the event through 5 different callbacks to get it back to the connected container. With Vuex, I can access the store in any component in one line and dispatch actions to the store from any component anywhere in the tree and rest easy knowing my component tree will update with the data changes. I'm seriously considering starting a re-write in Vue at this point because It's much easier to maintain and refactor.
comment 9y ago · link · parent
As a Southern California native, I am intimately familiar with the Mojave, Anza Borrego, and Sonora deserts. I will tell you that these deserts are far from "crappy land that nothing can grow on" as you put it.
The North American deserts are areas of huge ecological and geological diversity. They are also some of the most beautiful and awe-inspiring landscapes that exist on this planet.
We do utilize a lot of area in the Western Mojave for solar and wind power. For instance, there is a HUGE field of wind turbines in the San Gorgonio pass near Palm Springs at the intersection of the 10 and the 62.
That said, I am no way in favor of scarring any more of our deserts by covering "a fifth to a tenth" of them in solar panels. However, I am not against concentrated solar facilities several square miles in area as long as they remain contained.
I have thought about how we can "disperse" a solar panel network into a system of smaller panels and batteries and the best idea I can come up with is requiring all commercial buildings to cover their roofs in solar panels and maintain on-site battery banks. Also requiring all homes and apartment buildings to have at least one solar panel per household. These ideas come with their own trade-offs although.
comment 9y ago · link · parent
I thought the same thing. That's why I started using VueJS with Vuex. Vuex accomplishes the same things as redux in a much more manageable and centralized manner. Plus, you don't have to worry about connecting your components to the store through `react-redux` or whatever. With Vue and Vuex, you just pass the store object to the root view component and it's available in every single child component via `this.$store`. You can then `dispatch` actions which perform `commits` which call `mutations` which update the state. Then, in your component you create a computed property that uses a `getter` to return the piece of application state you want. It's a really simple top down data flow and everything is namespaced. It's so absurdly simple and easy that I don't understand why redux doesn't take a page from vuex's book.
I really should write a Vue + Vuex tutorial for beginners as I'm super happy with the way it works.
comment 9y ago · link · parent
comment 9y ago · link · parent
comment 9y ago · link · parent
> Do you think programming productivity is possible to measure and if so how?
For the purpose of discussion, I would propose that a team of developers are given a simple task with highly specific and explicit functionality requirements. This team of developers should Ideally have no experience with any of the technologies used. Experience with the problem domain is acceptable. These developers would then be tasked with building out the solution with various different technologies (languages, frameworks, libraries). We then compare the time it took for the developers to complete the task relative to the amount of bugs present in the solution. For example, the team could be tasked to build a gui calendar with Haskell and then Python.
The issues with the above proposed experiment are as follows:
* We would need to find some way to adjust for problem domain familiarity. The developers are going to get better, and thus more productive, at the task after they have completed it the first time.
* We need some sort of concrete numerical measure of "bug likelyness" for lack of a better term. All software has bugs, but some are very hard to find or appear only during runtime under very specific conditions.
* We need to decide whether or not we take the language ecosystem into account. In the calendar example I provided above, Python would obviously be more productive because there are a ton of different packages available that make creating a GUI extremely trivial.
* Do we take into account time spent on learning the language/tool/package/framework/library? Do we measure the amount of time that it takes the team to feel comfortable working with a new technology?
All in all, it's an interesting thought experiment and I'm interested to hear what you think.
comment 9y ago · link · parent
If you're interested in systems programming and want to try something new, I can recommend learning Nim: https://nim-lang.org/learn.html
If you're into PL implementation, you can't go wrong with: http://buildyourownlisp.com/ or http://www.craftinginterpreters.com/ or http://aosabook.org/en/500L/a-python-interpreter-written-in-...
If you want to try your hand at front-end web development, VueJs is pretty great: https://vuejs.org/
comment 9y ago · link · parent
comment 9y ago · link · parent
With Python(my bread and butter), I would simply use the built in intersection set class method: https://docs.python.org/3/library/stdtypes.html?highlight=se...
comment 9y ago · link · parent
I'm not the person you're replying to, but I do have something to say about this.
Your situation is a bit different in that you need to be able to get from Portland to SF and back in a single day. Some people, myself included, don't have that restriction and value the journey as much as we value the destination. Personally, I absolutely LOVE long road trips. Seeing sites, eating at cozy roadside diners, listening to super loud music and sleeping in my car are all things I look forward to.
comment 9y ago · link · parent
I sure hope not. Isolation only fuels nationalism. Nationalism fuels irrational decisions. Irrational decisions lead to fascism.
If you want your people to dehumanize a culture, the first step is to isolate your people from that culture. Don't allow your people any opportunity to empathize with that culture. If you continue to isolate your people, you can breed an "us vs them" sentiment. This is perfect if you want to start a war with popular support.
comment 9y ago · link · parent
I never have to worry about them going away and I can organize them into folders any way I like. Plus, they can be exported, imported, and shared. I use Firefox, so accessing the bookmarks is as simple as using a drop down menu. I actually use a bookmark tool bar for my ost frequently visited sites. This way, when I want to go to HN, for instance, I just click a single button and I'm there.
I've looked at other bookmarking software/services, and I still find that plain old browser bookmarks still fit every use case.
comment 9y ago · link · parent
It's got a fairly nice GUI and allows you to script events in a scripting language that's like a mix between Python and C++. You can also just use C++. Everything works as part of a "scene-tree". The physics and rendering engines are swappable. I believe it uses SDL2 by default. I'm pretty new at game-dev stuff. Most of my work is in back end web development. I just thought you may find it interesting or helpful.