- Aug 2023
-
www.countable.com www.countable.com
-
-
github.com github.com
-
If I find time between work and personal life I'll try to weigh in here, but those two things are keeping me pretty busy at the moment :)
-
just stopping by to say thanks for including me as an author on the commit. That's nice of you!
Tags
Annotators
URL
-
-
-
Before we move on to uploading an image, let’s give our users the ability to logout
-
Letting the User Logout
log out
-
-
-
let’s setup
let's set up
-
all setup
"all set up"
-
user’s will be able to
"users will"
-
-
www.flaticon.com www.flaticon.com
-
-
www.flaticon.com www.flaticon.com
Tags
Annotators
URL
-
-
edgeguides.rubyonrails.org edgeguides.rubyonrails.org
-
If you are using UUIDs instead of integers as the primary key on your models, you should set Rails.application.config.generators { |g| g.orm :active_record, primary_key_type: :uuid } in a config file.
-
-
stackoverflow.com stackoverflow.com
-
– Tyler Rick
-
I make a file named: app/models/active_storage/attachment.rb. Because it's in your project it takes loading precedence over the Gem version. Then inside we load the Gem version, and then monkeypatch it using class_eval: active_storage_gem_path = Gem::Specification.find_by_name('activestorage').gem_dir require "#{active_storage_gem_path}/app/models/active_storage/attachment" ActiveStorage::Attachment.class_eval do acts_as_taggable on: :tags end The slightly nasty part is locating the original file, since we can't find it normally because our new file takes precedence. This is not necessary in production, so you could put a if Rails.env.production? around it if you like I think.
-
I assume that the ActiveStorage::Attachment class gets reloaded dynamically and that the extensions are lost as they are only added during initialization. You’re correct. Use Rails.configuration.to_prepare to mix your module in after application boot and every time code is reloaded: Rails.configuration.to_prepare do ActiveStorage::Attachment.send :include, ::ActiveStorageAttachmentExtension end
-
-
www.digitalocean.com www.digitalocean.com
-
Since DigitalOcean will ignore it, you can set it to whatever value you’d like. The value unused in the example code makes it clear that you’re not using it.
-
-
github.com github.com
-
For lost googlers:
-
-
stackoverflow.com stackoverflow.com
-
application/xml: data-size: XML very verbose, but usually not an issue when using compression and thinking that the write access case (e.g. through POST or PUT) is much more rare as read-access (in many cases it is <3% of all traffic). Rarely there where cases where I had to optimize the write performance existence of non-ascii chars: you can use utf-8 as encoding in XML existence of binary data: would need to use base64 encoding filename data: you can encapsulate this inside field in XML application/json data-size: more compact less that XML, still text, but you can compress non-ascii chars: json is utf-8 binary data: base64 (also see json-binary-question) filename data: encapsulate as own field-section inside json
-
-
meta.stackoverflow.com meta.stackoverflow.com
-
I believe the final policy shall contain robust rationale and, in the best way possible, avoids the perception of rAIcial discrimination
-
Overall, because the average rate of getting correct answers from ChatGPT and other generative AI technologies is too low, the posting of answers created by ChatGPT and other generative AI technologies is substantially harmful to the site and to users who are asking questions and looking for correct answers.
-
The primary problem is that while the answers which ChatGPT and other generative AI technologies produce have a high rate of being incorrect, they typically look like the answers might be good and the answers are very easy to produce.
-
-
www.public.law www.public.law
-
Law is code that belongs to all of us
-
-
edgeguides.rubyonrails.org edgeguides.rubyonrails.org
-
The method name is generated by replacing spaces with underscores. The result does not need to be a valid Ruby identifier though — the name may contain punctuation characters, etc. That's because in Ruby technically any string may be a method name. This may require use of define_method and send calls to function properly, but formally there's little restriction on the name.
-
-
www.rootstrap.com www.rootstrap.com
Tags
Annotators
URL
-
-
-
Factory :video_file do file { fixture_file_upload 'test.png', 'image/png' } end
-
-
developer.chrome.com developer.chrome.com
-
Auto-update aside, you might also have found it hard to find a Chrome binary with a specific version. Google intentionally doesn’t make versioned Chrome downloads available, since users shouldn’t have to care about version numbers—they should always get updated to the latest version as soon as possible. This is great for users, but painful for developers needing to reproduce a bug report in an older Chrome version.
-
Due to there being no good way to solve these issues, we know that many developers download Chromium (not Chrome) binaries instead, although this approach has some flaws. First, these Chromium binaries are not reliably available across all platforms. Second, they are built and published separately from the Chrome release process, making it impossible to map their versions back to real user-facing Chrome releases. Third, Chromium is different from Chrome.
-
Auto-update: great for users, painful for developersOne of Chrome’s most notable features is its ability to auto-update. Users are happy to know they’re running an up-to-date and secure browser version including modern Web Platform features, browser features, and bug fixes at all times.However, as a developer running a suite of end-to-end tests you might have an entirely different perspective:You want consistent, reproducible results across repeated test runs—but this may not happen if the browser executable or binary decides to update itself in between two runs.You want to pin a specific browser version and check that version number into your source code repository, so that you can check out old commits and branches and re-run the tests against the browser binary from that point in time.None of this is possible with an auto-updating browser binary. As a result, you may not want to use your regular Chrome installation for automated testing. This is the fundamental mismatch between what’s good for regular browser users versus what’s good for developers doing automated testing.
-
-
github.com github.com
-
It is not intended to piecewise load rspec-rails.
.
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
def prevent_delivery_to_guests if @user && @user.guest? mail.perform_deliveries = false end end
-
-
stackoverflow.com stackoverflow.com
-
The Mailer is not the right place for business logic. When you use Sidekiq than your Job object should do the check before actually calling the Mailer.
-
-
stackoverflow.com stackoverflow.com
-
The Mailer, IMHO, is the wrong place for this logic. The mailer should do nothing but format and send messages. The logic to decide whether or not to send should be within the calling block of code.
-
-
github.com github.com
-
rendered.should have_selector("#header") do |header| header.should have_selector("ul.navlinks") end Both of which silently pass - however, capybara doesn't support a :content option (it should be :text), and it doesn't support passing blocks to have_selector (a common mistake from Webrat switchers).
-
- Jul 2023
-
stackoverflow.com stackoverflow.com
-
expect(described_class.active).not_to include_any_of [records_not_to_be_included]
-
-
www.imdb.com www.imdb.com
-
Unlike Turkophobic reviews I know real history behind WW1, Armenian gangs (most famous ones Henchak and Dashnak) killed lots of people and rob their neighbors. My mom side ancestors came from Van and I heard stories about Armenian neighbors came to rob them when their husbands went to war.Turkey suggested Armenia for a joint historians board for so-called Armenian Genocide research and opening state archives. Armenia denied their proposition.Let me explain this to you: you don't accept historians to decide, you praise (millions of) so-called Armenian Genocide supporter films without historical proof and if you see one film which just picture real situation it is propaganda. You say it is a propaganda because it conflicts with your propaganda.
-
You say it is a propaganda because it conflicts with your propaganda.
Tags
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
# if contract is passed use contract.start_date as date # Date.current otherwise # if date is given, the block is ignored. date { @overrides[:contract]&.start_date || Date.current }
-
-
stackoverflow.com stackoverflow.com
-
I know it might suck a little, but it sounds like the way to do it. As a thought though, if you're struggling with your tests it is usually a sign you'll struggle with it down the track and you should be redesigning the APIs. I can't see an alternative way of doing it, but you might be able to with the knowledge of the domain.
ugly/messy/less-than-ideal
-
-
-
I would say it's text when interpreted as text/plain it's human readable. Otherwise it's binary. That is, binary = for machines only.
-
Of course there are perversions like XMI and Microsoft's new formats.
-
the subversion FAQ http://subversion.tigris.org/faq.html#binary-files has = " ... if any of the bytes are zero, or if more than 15% are not ASCII printing characters, then Subversion calls the file binary. This heuristic might be improved in the future, however."
-
I couldn't find a definition of text except that text means absence of binary data. This is weak - so I would follow your definition - A text file is a file which can be read by a human.
-
I think the only purpose of this is to detain programmers from doing anything a non-Microsoft way.
Probably not really...
-
The distinction doesn't refer to the files _contents_ but how to the file is _treated_ when it is being read or written. In "rb"/"wb" modes files are left how they are, in "r"/"w" modes Windows programmers get line ends "\r\n" translated into "\n" what disturbs file positions and string lengths.
-
Dividing files into "text" and "binary" is the archetype misdesign in the operating system you use
-
-
euclideanspace.com euclideanspace.com
-
The XMI schema also extends the XML schema so that definitions of objects can be stored. This provives a way to hold a UML model.
-
XMI is a standard which defines how to serialise object instances. Although XML is a very good way to store information in a tree structured way, it is not object oriented. XMI extends XML to make it object oriented.
-
-
-
The representation of objects in terms of XML elements and attributes.
-
The standard mechanisms to link objects within the same file or across files.
-
XMI describes solutions to the above issues by specifying EBNF production rules to create XML documents and Schemas that share objects consistently.
-
Object identity, which allows objects to be referenced from other objects in terms of IDs and UUIDs.
-
-
en.wikipedia.org en.wikipedia.org
-
an object-oriented approach to data modelling – where data is described in terms of classes, attributes, and associations
-
-
-
en.wikipedia.org en.wikipedia.org
-
Conceptual data model: describes the semantics of a domain, being the scope of the model. For example, it may be a model of the interest area of an organization or industry. This consists of entity classes, representing kinds of things of significance in the domain, and relationship assertions about associations between pairs of entity classes. A conceptual schema specifies the kinds of facts or propositions that can be expressed using the model. In that sense, it defines the allowed expressions in an artificial 'language' with a scope that is limited by the scope of the model.
-
"Data models for different systems are arbitrarily different. The result of this is that complex interfaces are required between systems that share data. These interfaces can account for between 25-70% of the cost of current systems".
-
The term data model can refer to two distinct but closely related concepts
-
A data model can sometimes be referred to as a data structure, especially in the context of programming languages.
-
Sometimes it refers to an abstract formalization of the objects and relationships found in a particular application domain
-
A data model[1][2][3][4][5] is an abstract model that organizes elements of data and standardizes how they relate to one another and to the properties of real-world entities.
-
-
stackoverflow.com stackoverflow.com
-
Ruby 2.5+ If your substring is at the beginning of in the end of a string, then Ruby 2.5 has introduced the methods for this: delete_prefix for removing a substring from the beginning of the string delete_suffix for removing a substring from the end of the string
-
-
community.cisco.com community.cisco.com
-
I understand Duo follows the spec and attempts to make life easier by giving users the full 30 seconds, but unfortunately service providers don’t honor that recommendation, which leads to lockouts and a bunch of calls to our 1st line teams. You can’t tell users to stop using {platform}, but we can tell them to switch TOTP providers.
-
-
github.com github.com
-
We recommend using both an issuer label prefix and an issuer parameter, described below.
-
-
stackoverflow.com stackoverflow.com
-
The threat is that you're posting a secret key to a third party which violates a dozen of security best practices, nullifies the assumption of the key being "secret" and most likely violates your organization's security policy. In authentication all the remaining information can be guessed or derived from other sources - for example Referrer header in case of Google - and this is precisely why secrets should be, well, secret.
-
-
www.theguardian.com www.theguardian.com
-
The lawsuit against OpenAI claims the three authors “did not consent to the use of their copyrighted books as training material for ChatGPT. Nonetheless, their copyrighted materials were ingested and used to train ChatGPT.”
-
-
www.forbes.com www.forbes.com
-
One federal judge in the Northern District of Texas issued a standing order in late May after Schwartz’s situation was in headlines that anyone appearing before the court must either attest that “no portion of any filing will be drafted by generative artificial intelligence” or flag any language that was drafted by AI to be checked for accuracy. He wrote that while these “platforms are incredibly powerful and have many uses in the law,” briefings are not one of them as the platforms are “prone to hallucinations and bias” in their current states.
Seems like this judge has a strong bias against the use of AI. I think this broad ban is too broad and unfair. Maybe they should ban spell check and every other tool that could make mistakes too? Ultimately, the humans using the tool shoudl be the ones responsible for checking the generaetd draft for accuracy and the ones to hold responsible for any mistakes; they shouldn't simply be forbidden from using the tool.
-
New York-based startup DoNotPay created an AI-based way for people to contest traffic tickets—a user would wear smart glasses that would feed it information to say in court generated by AI—but before the creator could introduce it in court, he said he got threats from multiple bar associations about “unauthorized practice of law,”
-
he had used ChatGPT to conduct legal research for the court filing that referenced the cases and that the artificial intelligence tool assured him the cases were real.
-
-
stackoverflow.com stackoverflow.com
-
a = A.arel_table b = B.arel_table c = C.arel_table a .join(b) .on(a[:id].eq(b[:a_id])) .join(c, Arel::Nodes::OuterJoin) .on(b[:id].eq(c[:b_id])).to_sql
-
-
dba.stackexchange.com dba.stackexchange.com
-
But there is no absolute reason to use JOIN LATERAL (...) ON TRUE because you could just write it as a CROSS JOIN LATERAL instead
-
If you want to return a NULL-extended row in the case where the lateral join returns no rows, then you would use LEFT JOIN LATERAL (...) ON TRUE. Any condition other than TRUE is not necessary, as you could have just wrote it into the subquery itself
-
-
m.egwwritings.org m.egwwritings.org
Tags
Annotators
URL
-
-
www.codewithjason.com www.codewithjason.com
-
The way to do this with Capybara is documented on StackOverflow but, unfortunately, the answer there is buried in a little too much noise. I decided to create my own tiny noise-free blog post that contains the answer. Here it is:
-
I commonly find myself wanting to assert that a certain field contains a certain value.
-
-
www.humblebundle.com www.humblebundle.com
-
How we arrived in a post-truth era, when “alternative facts” replace actual facts, and feelings have more weight than evidence.Are we living in a post-truth world, where “alternative facts” replace actual facts and feelings have more weight than evidence? How did we get here? In this volume in the MIT Press Essential Knowledge series, Lee McIntyre traces the development of the post-truth phenomenon from science denial through the rise of “fake news,” from our psychological blind spots to the public's retreat into “information silos.”What, exactly, is post-truth? Is it wishful thinking, political spin, mass delusion, bold-faced lying? McIntyre analyzes recent examples—claims about inauguration crowd size, crime statistics, and the popular vote—and finds that post-truth is an assertion of ideological supremacy by which its practitioners try to compel someone to believe something regardless of the evidence. Yet post-truth didn't begin with the 2016 election; the denial of scientific facts about smoking, evolution, vaccines, and climate change offers a road map for more widespread fact denial. Add to this the wired-in cognitive biases that make us feel that our conclusions are based on good reasoning even when they are not, the decline of traditional media and the rise of social media, and the emergence of fake news as a political tool, and we have the ideal conditions for post-truth. McIntyre also argues provocatively that the right wing borrowed from postmodernism—specifically, the idea that there is no such thing as objective truth—in its attacks on science and facts.McIntyre argues that we can fight post-truth, and that the first step in fighting post-truth is to understand it.
-
-
activerecord-hackery.github.io activerecord-hackery.github.io
-
If Arel does not have the predicate you are looking for, consider monkey patching it:
-
-
-
Please do not use the issue tracker for personal support requests. Stack Overflow or GitHub Discussions is a better place for that where a wider community can help you!
-
Please consider adding a branch with a failing spec describing the problem.
-
File an issue if a bug is caused by Ransack, is new (has not already been reported), and can be reproduced from the information you provide.
-
-
-
Is the column a boolean column? (i.e. what does User.columns_hash[:admin_created].type return?)
-
-
activerecord-hackery.github.io activerecord-hackery.github.io
-
args: [:parent, :ransacker_args] do |parent, args|
-
Arel::Nodes::InfixOperation.new('->>', parent.table[:properties], 'link_type')
-
A timestamp like 2019-07-18 01:21:29.826484 will be truncated to 2019-07-18. But for your Rails application 2019-07-18 01:21:29.826484 is 2019-07-17 22:21:29.826484 at your time zone (GMT -03:00). So it should be truncated to 2019-07-17 instead.So, you should convert the timestamp to your current Rails time zone before extracting the date.
-
-
stackoverflow.com stackoverflow.com
-
ActiveStorage::LogSubscriber.detach_from :active_storage
It's nice that it's that easy to "opt out" of the default provided log subscriber and (if desired) swap in your own custom one that does whatever you want.
-
-
-
github.com github.com
-
Rails' default approach to log everything is great during development, it's terrible when running it in production. It pretty much renders Rails logs useless to me.
Really? I find it even more annoying in development, where I do most of my log viewing. In production, since I can't as easily just reproduce the request that just happened, I need more detail, not less, so that I have enough clues about how to reproduce and what went wrong.
-
Lograge is an attempt to bring sanity to Rails' noisy and unusable, unparsable and, in the context of running multiple processes and servers, unreadable default logging output.
-
-
github.com github.com
-
german.stackexchange.com german.stackexchange.com
-
But in almost all English sentences containing »there is«, these words do not mean »in this place is« but »it exists«. But the German words »da ist« do not have the meaning »it exists«. They only mean »in this place is«.
-
-
stackoverflow.com stackoverflow.com
-
This lets your test express a concept (similar to a trait), without knowing anything about the implementation: FactoryBot.create(:car, make: 'Saturn', accident_count: 3) FactoryBot.create(:car, make: 'Toyota', unsold: true) IMO, I would stick with traits when they work (e.g. unsold, above). But when you need to pass a non-model value (e.g. accident_count), transient attributes are the way to go.
traits and transient attributes are very similar
traits are kind of like boolean (either has it or doesn't) transient attribute flags
-
-
activeadmin.info activeadmin.info
-
You can also use the ActiveAdmin::FormBuilder as builder in your Formtastic Form for use the same helpers are used in the admin file:
.
-
semantic_form_for [:admin, @post], builder: ActiveAdmin::FormBuilder
semantic_form_for [:admin, @post], builder: ActiveAdmin::FormBuilder
-
-
www.metacritic.com www.metacritic.com
-
I really feel the game is a strong 9 but I’m giving it a 10 to offset the trolls.
-
-
www.kickstarter.com www.kickstarter.com
-
We all like games with a wide variety of resources, but most board games or card games never seem to have all that many. So let's do a comparison with popular games out there.
-
-
guides.rubyonrails.org guides.rubyonrails.org
-
Making MoneySerializer reloadable would be confusing, because reloading an edited version would have no effect on that class object stored in Active Job.
-
There, the module object stored in MyDecoration by the time the initializer runs becomes an ancestor of ActionController::Base, and reloading MyDecoration is pointless, it won't affect that ancestor chain.
-
-
stackoverflow.com stackoverflow.com
-
As this answer warns placing the include at the top level pollutes the Object namespace. Instead, I should have written
-
-
24-seven.churchcenter.com 24-seven.churchcenter.com
-
Shareable Code
For a second there, I thought this website was promoting open source and was actually sharing the (source) code for their website...
But alas, it's actually for sharing a different kind (QR) of code instead...
-
-
www.nintendolife.com www.nintendolife.com
-
Due to specific circumstances, there may be some devices that are incompatible even if they meet the specification requirements above.
-
-
www.kickstarter.com www.kickstarter.comThiefdom1
-
Buyer pays actual shipping charges instead of artificially raising prices so that they can have "free shipping".
Pitched as a positive when buying multiple copies (unfortunately, few buyers will have any need or desire to do so).
-
- Jun 2023
-
stackoverflow.com stackoverflow.com
-
Excellent, underrated answer!
-
As far as I see the current version of arel gem is not support FROM keyword for the sql query. You can generate a query using the SET, and WHERE keywords only,
-
-
www.soulcutter.com www.soulcutter.com
-
I’ve heard-suggested that ActiveSupport, which does a ton of monkey-patching of core classes, would make potentially-nice refinements. I don’t hold this opinion strongly, but I disagree with that idea. A big value proposition of ActiveSupport is that it is “omnipresent” and sets a new baseline for ruby behaviors - as such, being global really makes the most sense. I don’t know that anyone would be pleased to sprinkle using ActiveSupport in all their files that use it - they don’t even want to THINK about the fact that they’re using it.
-
Refinements themselves present a significant hurdle to adoption by virtue of their limitations and overall introduction of conceptual complexity. So it’s a tough sell to recommend this for anything outside of personal projects or places with incredibly strong esoteric Ruby knowledge (like, say, hidden away within Rails).
-
Let’s check out what the refinement approach looks like and why I consider it the best way to implement conversion wrappers.
-
under the name “conversion functions.” These exist in Ruby’s standard library - for example Array() is one that you’re likely to see in real code.
-
in the 10 years since they have been a part of Ruby, real life usages are astonishingly rare.
Tags
- good question
- Ruby
- unfamiliar
- programming idiom
- familiarity
- conversion (transform)
- why isn't this more popular?
- ruby: core extensions
- education
- monkey patching
- issues/factors hindering adoption
- where it shines / best application
- Ruby: refinements
- why is nobody using this?
- ubiquity
Annotators
URL
-
-
interblah.net interblah.net
-
-
What I do care about, though, is that we might start to accept and adopt opinions like “that feature is bad”, or “this sucks”, without ever pausing to question them or explore the feature ourselves.
-
Please – make a little time to explore Ruby. Maybe you’ll discover something simple, or maybe something wonderful.
-
If we hand most, if not all responsibility for that exploration to the relatively small number of people who talk at conferences, or have popular blogs, or who tweet a lot, or who maintain these very popular projects and frameworks, then that’s only a very limited perspective compared to the enormous size of the Ruby community.
-
I think we have a responsibility not only to ourselves, but also to each other, to our community, not to use Ruby only in the ways that are either implicitly or explicitly promoted to us, but to explore the fringes, and wrestle with new and experimental features and techniques, so that as many different perspectives as possible inform on the question of “is this good or not”.
-
If you’ll forgive the pun, there are no constants in programming – the opinions that Rails enshrines, even for great benefit, will change, and even the principles of O-O design are only principles, not immutable laws that should be blindly followed for the rest of time. There will be other ways of doing things. Change is inevitable.
Tags
- it's up to you to decide
- thinking/deciding/evaluating for yourself
- differences of opinion/perspective are good
- exploring
- community (for a project or product)
- responsibility
- self-learning
- newer/better ways of doing things
- why isn't this more popular?
- why is nobody using this?
- good point
- I agree
- Ruby: refinements
- critical thinking
- learning new things
- from different perspective/point of view
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
Tags
Annotators
URL
-
-
about.me about.me
-
-
stackoverflow.com stackoverflow.com
-
ON conflict (member_id) DO UPDATE SET
-
-
stackoverflow.com stackoverflow.com
-
rank() OVER (ORDER BY
first sighting: rank
-
-
github.com github.com
-
What is the Docker host filesystem owner matching problem?
-
-
stackoverflow.com stackoverflow.com
-
Using Time.now (which returns the wall-clock time) as base-lines has a couple of issues which can result in unexpected behavior. This is caused by the fact that the wallclock time is subject to changes like inserted leap-seconds or time slewing to adjust the local time to a reference time. If there is e.g. a leap second inserted during measurement, it will be off by a second. Similarly, depending on local system conditions, you might have to deal with daylight-saving-times, quicker or slower running clocks, or the clock even jumping back in time, resulting in a negative duration, and many other issues. A solution to this issue is to use a different time of clock: a monotonic clock.
-
-
stackoverflow.com stackoverflow.com
-
Certainly you could adapt the code to round rather than truncate should you need to; often I find truncation feels more natural as that is effectively how clocks behave.
What do you mean exactly? Compared clocks, or at least reading of them. What's a good example of this? If it's 3:55, we would say 3:55, or "5 to 4:00", but wouldn't probably say that it's "3".
-
-
stackoverflow.com stackoverflow.com
-
xargs -n 1 -I% git push origin :refs/tags/%
-
-
stackoverflow.com stackoverflow.com
-
First, although not directly relevant to the answer, it's important to remember that Git does not have remote tags. Git just has tags.
-
-
-
If you develop a pure frameworkless Ruby application or embed Ruby and don't need any of the listed integrations, you can depend on the airbrake-ruby gem and ignore this gem entirely.
Tags
Annotators
URL
-
-
bugs.ruby-lang.org bugs.ruby-lang.org
-
-
Random::Formatter#from_set(set, n = 16) (or Random::Formatter#from_set(n = 16, set: …))
-
I think that alphabet is still the right word here, as it’s sort of the "term of art" for this sort of thing, although set is probably a good name as well.
-
-
stackoverflow.com stackoverflow.com
-
What I have seen is situations where things were made horribly complicated to get around protections for which there was no need, and to try to guard the consistency of data structures that were horribly over-complicated and un-normalized.
-
Are protected members/fields really that bad? No. They are way, way worse. As soon as a member is more accessible than private, you are making guarantees to other classes about how that member will behave. Since a field is totally uncontrolled, putting it "out in the wild" opens your class and classes that inherit from or interact with your class to higher bug risk. There is no way to know when a field changes, no way to control who or what changes it. If now, or at some point in the future, any of your code ever depends on a field some certain value, you now have to add validity checks and fallback logic in case it's not the expected value - every place you use it. That's a huge amount of wasted effort when you could've just made it a damn property instead ;) The best way to share information with deriving classes is the read-only property: protected object MyProperty { get; } If you absolutely have to make it read/write, don't. If you really, really have to make it read-write, rethink your design. If you still need it to be read-write, apologize to your colleagues and don't do it again :) A lot of developers believe - and will tell you - that this is overly strict. And it's true that you can get by just fine without being this strict. But taking this approach will help you go from just getting by to remarkably robust software. You'll spend far less time fixing bugs.
In other words, make the member variable itself private, but can be abstracted (and access provided) via public methods/properties
-
Public and/or protected fields are bad because they can be manipulated from outside the declaring class without validation; thus they can be said to break the encapsulation principle of object oriented programming.
-
When you lose encapsulation, you lose the contract of the declaring class; you cannot guarantee that the class behaves as intended or expected.
-
Using a property or a method to access the field enables you to maintain encapsulation, and fulfill the contract of the declaring class.
-
It actually depends on if your class is a data class or a behaviour class.
first time I've come across this idea of data class vs. behavior class
-
Exposing properties gives you a way to hide the implementation. It also allows you to change the implementation without changing the code that uses it (e.g. if you decide to change the way data are stored in the class)
-
it still strikes me as something people believe in the abstract, rather than know from hard experience. I've always found that if you look behind/under widely held beliefs, you can find useful gems.
-
Python essentially doesn't have private methods, let alone protected ones, and it doesn't turn out to be that big a deal in practice.
-
Anything that isn't explicitly enforced by contract is vulnerable to misunderstandings. It's doing your teammates a great service, and reducing everyone's effort, by eliminating ambiguity and enforcing information flow by design.
-
Far more preferable is to minimize data structure so that it tends to be normalized and not to have inconsistent states. Then, if a member of a class is changed, it is simply changed, rather than damaged.
-
They are based on defensive coding carried to extremes.
-
Another point is that properties are good in that you can place breakpoints in them to capture getting/setting events and find out where they come from.
-
They sound like "argument by prestige". If MSDN says it, or some famous developer or author whom everybody likes says it, it must be so.
-
you nailed it! A consumer should only be able to set an object's state at initialization (via the constructor). Once the object has come to life, it should be internally responsible for its own state lifecycle. Allowing consumers to affect the state adds unnecessary complexity and risk.
-
to clarify, I am distinguishing between properties as representing state and methods representing actions
-
As soon as you make a member not-private, you are stuck with it, forever and ever. It's your public interface now.
-
also to clarify, by immutable I mean externally immutable - that is, consumers cannot affect the state. The class can internally affect its own state
-
Making a property writable adds an order of magnitude in complexity. In the real world it's definitely not realistic for every class to be immutable, but if most of your classes are, it's remarkably easier to write bug-free code. I had that revelation once and I hope to help others have it.
Tags
- properties vs. direct access to instance variables
- misunderstanding
- data flow
- explicit interfaces
- fallacy: treating an authority as infallible
- being explicit
- member visibility: make it private unless you have a good reason not to
- well-intentioned protections causing pain or overly complicated workarounds
- breaking encapsulation
- overly complicated
- defensive coding carried to extremes
- +0.9
- learned from real-world experience
- immutable data/objects/members to prevent bugs
- good idea
- properties vs. methods
- member visibility: once it is public, you're stuck with it in public API forever
- first sighting
- encapsulation (programming)
- to make debugging easier
- distinction
- eliminate ambiguity
- doing something because someone prestigious says to
- using properties to abstract, encapsulate, and control access to private instance variables/data
- contract (programming)
- theory vs. practice
- avoid complexity
- clarification
- I agree
- good point
- normalizing data
- Python
- keeping software simple to prevent bugs
- not actually a problem in practice
- by design
Annotators
URL
-
-
stackoverflow.com stackoverflow.com
-
Have you ever: Been disappointed, surprised or hurt by a library etc. that had a bug that could have been fixed with inheritance and few lines of code, but due to private / final methods and classes were forced to wait for an official patch that might never come? I have. Wanted to use a library for a slightly different use case than was imagined by the authors but were unable to do so because of private / final methods and classes? I have.
-
Conversely, I've never in 16+ years of professional development regretted marking a method protected instead of private for reasons related to API safety
-
Let me preface this by saying I'm talking primarily about method access here, and to a slightly lesser extent, marking classes final, not member access.
-
Typical control-freak opinion.
-
I just wanted to tweak Java's BufferedReader to handle custom line delimiters. Thanks to private fields I have to clone the entire class rather than simply extending it and overriding readLine().
-
Practically speaking, if you can't think of a reason why it would be dangerous then theres more to be gained by opting for extensibility.
-
Also, people prefer association over inheritance so protected as default is difficult to perceive
-
I'm not saying never mark methods private. I'm saying the better rule of thumb is to "make methods protected unless there's a good reason not to".
-
Marking methods protected by default is a mitigation for one of the major issues in modern SW development: failure of imagination.
-
If it's dangerous, note it in the class/method Javadocs, don't just blindly slam the door shut.
-
I can't count the number of times I've been wrong about whether or not there will ever be a need to override a specific method I've written.
-
It often eliminates the only practical solution to unforseen problems or use cases.
-
When a developer chooses to extend a class and override a method, they are consciously saying "I know what I'm doing." and for the sake of productivity that should be enough. period.
-
member access
I assume this is making a disctinction between methods (member functions) and member/instance variables
-
Been disappointed, surprised or hurt by a library etc. that was overly permissive in it's extensibility? I have not.
-
The old wisdom "mark it private unless you have a good reason not to" made sense in days when it was written, before open source dominated the developer library space and VCS/dependency mgmt. became hyper collaborative thanks to Github, Maven, etc. Back then there was also money to be made by constraining the way(s) in which a library could be utilized. I spent probably the first 8 or 9 years of my career strictly adhering to this "best practice". Today, I believe it to be bad advice. Sometimes there's a reasonable argument to mark a method private, or a class final but it's exceedingly rare, and even then it's probably not improving anything.
Tags
- give the benefit of the doubt
- only supporting some/specific/limited use cases
- failure of imagination
- annotation meta: may need new tag
- reasonable defaults
- member visibility: make it public/protected by default so others can override/extend as needed
- surprising
- not extensible enough
- subclassing/inheritance
- member visibility: make it private unless you have a good reason not to
- +0.9
- don't be so rigid
- inadvertently causing problems for future self
- dangerous (programming)
- inheritance (programming)
- member visibility
- allow others take the responsibility/risk if they want; don't just rigidly shut the door to even the possibility
- not:
- do pros outweigh/cover cons?
- please elaborate
- inextensible
- never say never
- data/properties vs. methods
- bad advice
- rule of thumb
- inadvertently preventing possibility of solving unforseen problems or use cases
- you can't possibly know
- disappointing
- well-intentioned protections causing pain or overly complicated workarounds
- it's your responsibility to handle that
- can't think of everything
- learned from real-world experience
- can't predict the future
- member visibility: protected vs. private
- rigid/inflexible
- rigidness/inflexibility
- control freak
- taking on the responsibility
- what does this actually mean?
- you can't know for sure
- good point
- extensibility
- member visibility: make it protected unless you have a good reason not to
- software development
- inadvertently causing problems for future users
Annotators
URL
-
-
en.wikipedia.org en.wikipedia.org
-
It is a type of class attribute (or class property, field, or data member).
Tags
Annotators
URL
-
-
www.typescriptlang.org www.typescriptlang.org
-
The main thing to note here is that in the derived class, we need to be careful to repeat the protected modifier if this exposure isn’t intentional.
-
Derived classes need to follow their base class contracts, but may choose to expose a subtype of base class with more capabilities. This includes making protected members public:
-
TypeScript offers special syntax for turning a constructor parameter into a class property with the same name and value. These are called parameter properties
Doesn't this violate their own non-goal #6, "Provide additional runtime functionality", since it emits a
this.x = x
run-time side effect in the body that isn't explicitly written out in the source code? -
Member Visibility
-
-
developer.mozilla.org developer.mozilla.org
-
-
The major use case of Reflect is to provide default forwarding behavior in Proxy handler traps. A trap is used to intercept an operation on an object — it provides a custom implementation for an object internal method. The Reflect API is used to invoke the corresponding internal method. For example, the code below creates a proxy p with a deleteProperty trap that intercepts the [[Delete]] internal method. Reflect.deleteProperty() is used to invoke the default [[Delete]] behavior on targetObject directly.
-
-
stackoverflow.com stackoverflow.com
-
Reflection adds the ability to reverse-engineer classes, interfaces, functions, methods and extensions. Additionally, they offers ways to retrieve doc comments for functions, classes and methods.
-
-
help.openai.com help.openai.com
-
What's the structure of the URL of a shared link?https://chat.openai.com/share/<conversation-ID>
I've never seen a website document something like this before... especially as part of a FAQ.
How/why is this information helpful to people?
-
If I continue the conversation after I create a shared link, will the rest of my conversation appear in the shared link?No. Think of a shared link as a snapshot of a conversation up to the point at which you generate the shared link. Once a shared link is created for a specific conversation or message, it will not include any future messages added to the conversation after the link was generated. This means that if you continue the conversation after creating the shared link, those additional messages will not be visible through the shared link.
-
The conversation will no longer be accessible via the shared link, but if a user imported the conversation into their chat history, deleting your link will not remove the conversation from their chat history.
-
Are shared links public? Who can access my shared links?Anyone who has access to a shared link can view and continue the linked conversation. We encourage you not to share any sensitive content, as anyone with the link can access the conversation or share the link with other people.
-
-
Shared links offer a new way for users to share their ChatGPT conversations, replacing the old and burdensome method of sharing screenshots.
-
-
www.imdb.com www.imdb.com
-
it's not asking anymore of you than to just enjoy
-
-
stackoverflow.com stackoverflow.com
-
Depends on the style guide you follow for your project. The popular Ruby Style Guide says to "Avoid using Perl-style special variables (like $:, $;, etc. ). They are quite cryptic and their use in anything but one-liner scripts is discouraged."
-
When I first got started with Ruby, I obviously thought that $LOAD_PATH was better. But once you've graduated from beginner status, I'd only use $LOAD_PATH if I was trying to make my code more readable to a beginner. Meh its a trade off.
-
The Ruby load path is very commonly seen written as $: , but just because it is short, does not make it better. If you prefer clarity to cleverness, or if brevity for its own sake makes you itchy, you needn't do it just because everyone else is. Say hello to ... $LOAD_PATH ... and say goodbye to ... # I don't quite understand what this is doing... $:
-
-
www.indiegogo.com www.indiegogo.com
-
“So superior mechanically to other crowdsourced games, it was banned on Kickstarter and Gamefound!”
-
-
-
global.rakuten.com global.rakuten.com
Tags
Annotators
URL
-
-
global.rakuten.com global.rakuten.com
-
Mikitani
-
-
www.postgresql.org www.postgresql.org
-
typical use would be to reference a json or jsonb column laterally from another table in the query's FROM clause.
-
Writing json_populate_record in the FROM clause is good practice, since all of the extracted columns are available for use without duplicate function calls.
-
-
www.optimizesmart.com www.optimizesmart.com
-
Debug mode allows you to see only the data generated by your device while validating analytics and also solves the purpose of having separate data streams for staging and production (no more separate data streams for staging and production).
good to know.
Seems to contradict their advice on https://www.optimizesmart.com/using-the-ga4-test-property/ to create a test property...
-
-
organicdigital.co organicdigital.co
-
They create a lot of useful content on there site, which they are happy for users to copy and paste for use elsewhere. They wanted to know how often this was happening, on which pages, and what text.
-
-
stackoverflow.com stackoverflow.com
-
but I literally posted a screenshot of it working. So you must be doing something wrong.
-
-
support.google.com support.google.com
-
To use the tool, you need the following access: Viewer role for the Universal Analytics property Editor role for the Google Analytics 4 property After you've installed and activated the Google Sheets add-on (below), follow these steps: Import audience definitions from your Universal Analytics property to a Google Sheet. Decide how you want to export audiences from your Google Sheet to your Google Analytics 4 property (e.g., using the existing definition or modifying the definition first in the tool, then exporting). Export your audiences from the Google Sheet to your Google Analytics 4 property.
Seems simple enough. With a lot of power/flexibility to make any changes in between the import and export steps.
-
-
support.google.com support.google.com
-
(New name for Collaborate permission.)
Analyst
Tags
Annotators
URL
-