Ask HN: Is “Hacker News” becoming “News”?
4 pointsby cessor2 comments
migrations/0006_add_modeltranslation.py
migrations/0007_remove_temp_fields.py
migrations/0008_remove_language_field.py
migrations/0009_alter_page_slug.py
migrations/0010_alter_menuitem_absolute_url.py
While they aren't semantically rich ('Why did you change absolute url on menu item?') I found that they are easy to distinguish and navigate. function createEmployee(firstName, lastName) {
return {
firstName: firstName,
lastName: lastName,
};
}
OO-Programs have these weird factory functions called constructors that do exactly that. To me, it makes sense that such functions should share their living space with the class that they are creating. Where else would you like to put these functions? "Utils"? class SayHello {
public static void toPerson(String name) {
System.out.println("Hello " + name);
}
}
Sure, comparing it to an empty Python file which just says "print" this looks like an aweful lot of code. However if the paradim is poorly understood, it will seem to be working against you: class Name {
public Name (string name) {
this.name = name;
}
public static void greet() {
System.out.println("Hello " + this.name);
}
}
The programming is different in that you create a declarative network of objects that then ... act. At this level, there is hardly any difference, except that the name has been introduced as a proper concept. Many people will argue that such value objects are expensive or inefficient (which they are) but if that cost hits you hard, you should be asking yourself why you picked a high level language to begin with. def f():
x = 5
class Blub:
def incx(self):
nonlocal x
x += 1
def getx(self):
return x
return Blub()
j = f()
j.incx()
print(j.getx())
This will print 6, as expected. open('file.txt').read()
be, when the current user does not have permissions to read file.txt? status, content = read('file.txt')
content = read('file.txt', &status)
status = read(&content)
I wouldn't argue against any of them, although I have my preferences of course. I like the exception model here, but you are right, rare exceptions, communicated poorly can be surprising and painful. >>> def a(u, v):
... def b():
... return u + v
... return b
...
>>> b = a(1,2)
>>> b()
3
Like this, there is no way to access u & v from b.
[1] https://docs.djangoproject.com/en/5.1/topics/i18n/translatio...