![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I think I got it where all this bs about passing around numerical ids of entities instead of entity references (maybe lazy) come from. It's like 'error code'. It comes from the ancient c programming, where we just could not allocate a string for a readable piece of text, or for the data that may need some efforts to instantiate or allocate.
In short. It's stupid to pass around "ids" in a program.
In short. It's stupid to pass around "ids" in a program.
no subject
Date: 2015-10-01 09:10 pm (UTC)no subject
Date: 2015-10-01 09:44 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2015-10-01 09:25 pm (UTC)What if you are passing "ids" to database (to retrieve full records)?
Is it still stupid?
no subject
Date: 2015-10-01 09:45 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2015-10-01 09:26 pm (UTC)Потом ещё великолепны будут способы вычисления уникальности.
no subject
Date: 2015-10-01 09:43 pm (UTC)so what do you do if you actually DO fail to allocate? you pass an exception through whatever means. Let's now talk about how your cyclomatic complexity affects your ability to reason about correctness of your program.
If you never learnt to code in imperative programming languages (such as C/C++), it doesn't exactly mean that those that did learn are stupid or something.
< /rant>
no subject
Date: 2015-10-01 09:46 pm (UTC)They are not stupid. They are just from an old age. mid-XX century.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2015-10-01 09:47 pm (UTC)no subject
Date: 2015-10-02 12:33 am (UTC)(no subject)
From:no subject
Date: 2015-10-01 11:36 pm (UTC)no subject
Date: 2015-10-02 12:33 am (UTC)no subject
Date: 2015-10-02 12:07 am (UTC)Numerical ids are much better.
>It's like 'error code'.
No it’s not.
You can store them in a CPU register.
You can save them using only 8 bytes of storage.
You can compare them with a single cmp CPU instruction.
You can design your system so the IDs are unique even if your system will scale out to thousands of servers.
no subject
Date: 2015-10-02 12:36 am (UTC)And I never suggested to pass around internal references outside. This may be an interesting problem, passing around internal references; even a numerical id is an internal reference if we look from outside. I routinely talk to our analysts like this - "did it work now for account number 10567"? Now imagine... well, we all know how it is. Phone number (why the fuck it is still a number?), SSN, card number (why number?), etc.
(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2015-10-02 04:32 am (UTC)> You can save them using only 8 bytes of storage.
> You can compare them with a single cmp CPU instruction.
These are all "C" concerns. The difference is that for Vlad "C" language (and a CPU register) sounds like something from the age of pyramids, while for embedded developers this is painful present.
> You can design your system so the IDs are unique
This does not really say something in favor or against passing "naked" IDs vs lazy entities. You can pass around lazy entities with unique IDs.
no subject
Date: 2015-10-02 03:59 am (UTC)Databases are designed to get mass quantities of records in one shot. E.g. retrieving 10,000 records via some simple query (
SELECT * FROM Users WHERE OrganizationId=125
) is virtually instantaneous. Lazy entity references are designed to get one object at a time. Retrieving 10,000 records via 10,000 queries (SELECT * FROM Users WHERE UserId=n
x10,000 times) will take forever.ORMs like Hibernate do provide lazy references, and make things look easy on toy databases. However, this ease is deceiving. Later on you find yourself rewriting half of the program getting rid of the lazy references, because it just does not work fast enough in production.
no subject
Date: 2015-10-02 06:27 am (UTC)C programmers have other sins. Often they mix numbers that are identifiers for different things. I once coined for myself a label after working some legacy codebase: "program composed from integers". If highest abstraction in a code you have to ship is integer you know you're screwed.
no subject
Date: 2015-10-02 10:03 am (UTC)But what we have are layers and layers of performance-killing wrappers like in (N)Hibernate and it`s much easier to work with simple types (long,int,whatever) in record fields.
Also these wrappers are not actually transparent. Simple long id cannot cause a LazyInitializationException, unlike some wrapper with reference to long-closed Session.
no subject
Date: 2015-10-02 02:42 pm (UTC)(no subject)
From:(no subject)
From:no subject
Date: 2015-10-02 12:13 pm (UTC)If all your strings are static and already loaded in some array, the ID will save you trouble to load them each time. Or, if you have some resource provider, like Android does, it will let you to have multi-language support with no cost at all.
no subject
Date: 2015-10-02 02:40 pm (UTC)(no subject)
From:(no subject)
From:(no subject)
From:(no subject)
From:no subject
Date: 2015-10-02 12:29 pm (UTC)(из чего следует, что id для этих целей должен быть красивым и человекочитаемым, например, 137-234-987-202. И вообще генерироваться отдельно, не совпадать с внутренним id, который, как правило, UUIDv4, коих should be enough for everyone).
Ну и ещё из джаваскрипта в скалу приходится id явно гонять, референс же полностью не воссоздать. А так, внутри скального кода, конечно, никаких явных id, кашрут не велит.
no subject
Date: 2015-10-02 02:39 pm (UTC)1. id вместо сообщения об ошибке (содержащего конкретные детали)
2. перепасовка целых чисел в коде, вместо type-safe конкретных указателей на объекты
3. использование целых чисел для идентификации явлений природы
По третьему вопросу - конечно, нужен способ; но почему именно десятичные цифры, я не понимаю. base36 для меня звучало бы более осмысленно. BC-4KSNL, то ли дело. Запоминается мгновенно, как мем.
(no subject)
From:id vs pointer
Date: 2015-10-02 01:36 pm (UTC)2. It does not have to live on the same cpu.
3. And there are no life time issues - stale ids are trivially detected.
Re: id vs pointer
Date: 2015-10-02 04:51 pm (UTC)3. tell me about it
no subject
Date: 2015-10-04 09:17 pm (UTC)> In short. It's stupid to pass around "ids" in a program.
не очень осмотрительно представлять свой очень специфический use case как "всегда" и "везде". это очевидный bias, но надо же себя заставлять.
вообще меня удивляет, как ты дожил до преклонных лет, а до сих пор не знаешь, что правильный ответ на любой вопрос - it depends.
например, я в основном работаю с данными, которые не влезают в память одной машины любого осмысленного размера. мысли создавать врапперы над числовыми id в такой обстановке даже зародиться неоткуда.