Jump to content

Wikipedia:Reference desk/Computing

From Wikipedia, the free encyclopedia
Welcome to the computing section
of the Wikipedia reference desk.
Select a section:
Want a faster answer?

Main page: Help searching Wikipedia

   

How can I get my question answered?

  • Select the section of the desk that best fits the general topic of your question (see the navigation column to the right).
  • Post your question to only one section, providing a short header that gives the topic of your question.
  • Type '~~~~' (that is, four tilde characters) at the end – this signs and dates your contribution so we know who wrote what and when.
  • Don't post personal contact information – it will be removed. Any answers will be provided here.
  • Please be as specific as possible, and include all relevant context – the usefulness of answers may depend on the context.
  • Note:
    • We don't answer (and may remove) questions that require medical diagnosis or legal advice.
    • We don't answer requests for opinions, predictions or debate.
    • We don't do your homework for you, though we'll help you past the stuck point.
    • We don't conduct original research or provide a free source of ideas, but we'll help you find information you need.



How do I answer a question?

Main page: Wikipedia:Reference desk/Guidelines

  • The best answers address the question directly, and back up facts with wikilinks and links to sources. Do not edit others' comments and do not give any medical or legal advice.
See also:


July 25

[edit]

Are there apps or any software, that can identify one's accent?

[edit]

E.g, software that can identify a person's native language, when they are currently speaking in a non-native language (e.g. English), rather than in their native language we want to identify.

Yesterday, I presented this question at the language reference desk. However, no one has given me a positive answer yet, except for a possible direction via AI, but without a certain answer. 2A06:C701:7B31:C100:7D63:C50F:C3A5:9744 (talk) 10:18, 25 July 2024 (UTC)[reply]

You received a comprehensive answer at the language desk. The answer is no. Shantavira|feed me 11:48, 25 July 2024 (UTC)[reply]
AI is used for pattern matching and classification. If there is some pattern that classifies speech as having a specific accent, AI can identify the pattern and classify the accent. AI is not magic. It won't do any more than identify a pattern using one of the many methods of pattern matching and then classify using one of the many ways of clustering and classification. 75.136.148.8 (talk) 12:12, 25 July 2024 (UTC)[reply]
A more precise answer is that no respondent here is aware of the existence of such an app. Perhaps the NSA has developed one but is keeping it under wraps. If so, how would we know?  --Lambiam 13:33, 25 July 2024 (UTC)[reply]
It is likely that, for the moment, it is far easier and cheaper to employ non-Artificial Intelligences, i.e. people, with linguistic expertise that enables them to make such identifications. This of course would only apply to specific instances – an AI-like application would be needed for automatic surveillance on a mass scale. {The poster formerly known as 87.81.230.195} 94.2.67.235 (talk) 00:18, 28 July 2024 (UTC)[reply]
People on Hugging Face have created some accent related models but putting that into some piece of software you can use will be a very much do-it-yourself task. Models found there also have rather variable quality, most of them are research projects not intended for wider consumption. With enough data, classifying existing accents in order to infer other accents should be possible. But, speaking anecdotally as someone who grew up in world cities, the way someone learns a language hugely influences their accent... possibly about equally to the languages they spoke before that, and the possibility for error is huge.
Again speaking anecdotally: You should think of accents as individual but similar to each other - usually a property of how that specific person has used and learned their languages, but sometimes completely learned and how that person wishes to speak. You should approach whatever problem you are trying to solve with this in mind, it is not just a symptom of a person's previous languages. Komonzia (talk) 21:13, 3 August 2024 (UTC)[reply]

How to automatically search and replace text in Linux CLUI in a multi-lined way?

[edit]

We can automatically search and replace single-lined text in Linux CLUI with awk and sed, but I need a way to do it multi-lined.

  • File A has several HTML structures.
  • File B has this HTML structure:
    <footer class="site-footer">
      <div class="site-footer__inner container">
        {{ page.footer_top }}
        {{ page.footer_bottom }}
      </div>
    </footer>
  • File C has this HTML structure:
    <footer class="site-footer">
      <div class="site-footer__inner container">
        {{ page.footer_top }}
        {{ page.footer_bottom }}
      </div>
      <span class="globalrs_dynamic_year">{{ 'now' | date('Y') }}</span>
    </footer>

How to automatically search in file A and if it contains the text of file B then replacing that text with the text of file C?

How would you do this with C/Perl/Python/PHP/Node.js or something else? 103.199.70.159 (talk) 19:06, 25 July 2024 (UTC)[reply]

While it would be trivial to do this in Python or any other reasonable programming language, if I wanted to do this with a script, my approach would be:
  1. . Convert all three files to a version which eliminates newlines, using sed. For convenience, I would replace the newline character with some character or string which would not occur in the HTML, call it '~' (tilde).
  2. . Now add a newline to change the tilde in every occurrence of "</footer>~" to a newline in each of the three converted files. Do the same for "~<footer class="site-footer">". You end up with files where the html of interest is on a single line.
  3. . Use sed to do the substitution of the single line file C text to replace the single line file B text in the single line file A text.
  4. . Use sed to convert single line file A back to the original formatting by replacing '~' with newline.
This won't work if files B and C are not marked with the exact footer head and tail as you have shown.-Gadfium (talk) 20:46, 25 July 2024 (UTC)[reply]
In any programming langauge, A, B, and C are just text. So, you use a string replace function. In C++, it is (from memory) replace(A,B,C);. In Perl (again from memory), it is A=~s/B/C/;. In PHP, it is $A=str_replace($B,$C,$A);. In Python, it is A = A.replace(B,C);. In Node.js it is A = A.replace(B,C) as well. Note that in a programming language, a string is just a string of characters. It doesn't care if there are newline or return characters in it. So, replacing a substring replaces it all, including the return and newline characters. But, the text has to match perfectly. For example, if A is using two spaces for indentation and B is using tab characters, it won't match. Similarly, if one uses all lower case tag names and another uses all upper case tag names, it won't match. In that case, you need to reformat the text so it is all the same or use regular expressions. 75.136.148.8 (talk) 13:31, 26 July 2024 (UTC)[reply]
The Unix/Linux utility sed can do this; see sed § Multiline processing example. The search ["sed" multi-line replace] gives some more examples.  --Lambiam 23:01, 26 July 2024 (UTC)[reply]
Since the OP asked for a Perl solution, here is a simple one.
my $orig = `cat $ARGV[0]`;
my $repl = `cat $ARGV[1]`;
my $text = `cat $ARGV[2]`;
$text =~ s:$orig:$repl:g;
print $text;
CodeTalker (talk) 18:57, 27 July 2024 (UTC)[reply]

July 27

[edit]

Fast Fourier transform

[edit]

Can a relational database, with its set of rows and columns, support the computerization of the Fast Fourier transform ? Afrazer123 (talk) 04:40, 27 July 2024 (UTC)[reply]

No. The FFT algorithms require computations based on the indices. This is not supported by relational databases. The notion of index is in fact alien to the relational model, which is essentially an unordered set of tuples (the rows) of named values (as identified by the row names). One can add the index as a key, basically an extra column, but this does not help. The SQL-type languages that come with such databases also do not support the recursion used by FFT algorithms.  --Lambiam 13:18, 27 July 2024 (UTC)[reply]
Thanks for the reply. How pulsating! It seems there's a discharge of some sort which apparently isn't taken into consideration by the RDB while using an extra column (key) only exacerbates things. Also, SQL appears to be to confining, off-limits for the algorithm's recursion. Afrazer123 (talk) 02:09, 28 July 2024 (UTC)[reply]

July 28

[edit]

Turning Off Ad Blocker

[edit]

If I am using Firefox and Windows 11, and a web site asks me to turn off my ad blocker, and I don't know what ad blocker I am using, how do I determine what ad blocker I am using, so that I can turn it off? This is sort of a strange question, because I don't want to deal with ads, but I would rather just ignore the ads than deal with web sites that aggressively fight ad blocking. I do have Norton Safe Web. I don't know if it tries to block ads. Robert McClenon (talk) 00:23, 28 July 2024 (UTC)[reply]

Hi, Robert McClenon! In Windows 10 which I'm on, such blockers appear (with other things) in a drop-down list of 'Extensions' found by clicking a jigsaw-puzzle corner piece at the top right corner of the Firefox window. I had a similar problem (with YouTube) until I discovered that Malwarebytes had added ad blocking to its functions. Hope this helps. {The poster formerly known as 87.81.230.195} 94.2.67.235 (talk) 20:54, 28 July 2024 (UTC)[reply]
The better way to get around this is to reconfigure your RAM firewall to exclude cloud analytic encryption on your virtual platform. Pretty simple fix, will take about 30 seconds. Jidarave (talk) 21:49, 28 July 2024 (UTC)[reply]
The above post is nonsensical. Philvoids (talk) 22:53, 28 July 2024 (UTC)[reply]
This is probably the same troll who reappears here periodically to post gibberish like this before getting blocked. CodeTalker (talk) 06:52, 29 July 2024 (UTC)[reply]
It looks like perfectly legit response from AI. Maybe someone is training their bot to replace human editors on Wikipedia. 75.136.148.8 (talk) 12:50, 29 July 2024 (UTC)[reply]
The responses by LLMs tend to read like something a human could actually have written as a reasonable response, using terms from the question. This response does not. It looks contrived to sound impressive while making no sense whatsoever.  --Lambiam 22:51, 29 July 2024 (UTC)[reply]
I'm glad it's confirmed to make no sense, because although I didn't understand it, I feared that to be because of my limited knowledge of IT.
This sidetrack being dealt with, can anybody give a better answer than mine to the OP's query? {The poster formerly known as 87.81.230.195} 94.2.67.235 (talk) 18:03, 30 July 2024 (UTC)[reply]
Will I need a turboencabulator for this? -insert valid name here- (talk) 16:36, 6 August 2024 (UTC)[reply]
A long shot, but are you using NoScript in Firefox by any chance? It's a kind of an ad-blocker on steroids and because it completely blocks scripts (unless you allow them) it can be difficult to know what's getting blocked. Using the "temporary allow" function usually gets me past things, but sometimes I end up having to switch to incognito mode (which I have setup to run without NoScript). Matt Deres (talk) 16:02, 31 July 2024 (UTC)[reply]
In Firefox's Privacy and Security settings, if you have tracking protection set to Strict, try setting it back to Standard. This should help. win8x (talking | spying) 20:19, 31 July 2024 (UTC)[reply]

July 29

[edit]

Can you delete and then undelete your twitter account?

[edit]

This is about the incident with Pete Souza and an intactly-eared Donald Trump photo.[1] Souza apparently deleted his twitter account after both he and the Trump photographer took heat. Question: can he undelete it later, and get his old tweets back? I mean using normal Twitter features. Presumably someone famous like Souza could get Elon's, um, ear for a special request, but let's not count that. Thanks. 2602:243:2008:8BB0:F494:276C:D59A:C992 (talk) 23:39, 29 July 2024 (UTC)[reply]

According to [2] you have 30 days to reactivate your account. After that, it cannot be recovered. RudolfRed (talk) 15:50, 30 July 2024 (UTC)[reply]


July 31

[edit]

Alternating between dark and light mode?

[edit]

I work on Google Sheets spreadsheets all day and I don't like how bright light mode gets during sunset. I don't like the look of dark mode either, so I'd prefer to only use dark mode during the sunset time or night. Does anyone know if this is a thing that Google has allowed for? Is there an extension that does this? I could try making a Chrome extension but this is not something I have done before. ―Panamitsu (talk) 05:46, 31 July 2024 (UTC)[reply]

Google Maps does this automatically when in satnav mode, but I don't know if it is extendable to other products. -- Verbarson  talkedits 10:30, 31 July 2024 (UTC)[reply]
Neither of the above are exactly what you want, but it might come close. The "colour temperature adjustment" apps might be closer to what you actually want, since it isn't dark mode. Things get slightly more 'red' when it is active, but your eyes will get used to it - I use it myself. Komonzia (talk) 20:57, 3 August 2024 (UTC)[reply]

August 1

[edit]

Tweaking the "Format Axis" options in Excel

[edit]

If you have a chart or pivot chart in Excel, you can double click on the X axis to bring up a pane that gives you all kinds of formatting options, including setting minimum and maximum bounds for the graph. So, you can set the maximum value to be $1,000 and any values that go above that either don't display or are cut off (depending on the chart type). My problem is that, I need to set such a maximum, but I want it to truly act like a maximum value instead of a set number. Like, if the user's choice of filters means that the chart never comes near the boundary I set, then the upper and lower limits should behave dynamically. Is there a way to do that?
If that's hard to picture, here's an example: we sell 10-20 apples and 200-300 oranges each month, so the monthly totals are mostly around 250 or so. But one month we had a crazy value: we sold 10,000 oranges. The chart is unreadable if we leave the defaults in, so we set a maximum value of, say, 350. Now we can read it. But if the user selects "apples" from the filter, the graph becomes unreadable the other way around: we've forced the upper bound of the X-axis to be 350 and the apples are now just a ripple across the bottom of the chart. What I want is for Excel to dynamically resize the chart like it normally does, but not go past my maximum. Can it be done? Googling has not been fruitful so far. Matt Deres (talk) 19:11, 1 August 2024 (UTC)[reply]

I understand that you do not want to chart dynamically all the monthly apple totals. Instead you may chart dynamically the minimum of two values, viz. each month's apple total and a numerical limit of 350. Use the Excel MIN function. Philvoids (talk) 18:19, 2 August 2024 (UTC)[reply]
Sorry, that is completely unrelated to what I'm talking about. I'm trying to control the way the graphs establish limits to the X-axis. Matt Deres (talk) 01:43, 3 August 2024 (UTC)[reply]

August 3

[edit]

newline

[edit]

If you use {{subst:Welcome-newuser|heading=no}} it insert an extra newline at the top. Can that be fixed? Thanks, Polygnotus (talk) 02:20, 3 August 2024 (UTC)[reply]

This is not a good place to ask; try instead Template talk:Welcome, or, if that yields no response, Wikipedia:Village pump (technical). I can report that the extra newline issue already appears for just {{Welcome|heading=no}}.  --Lambiam 11:47, 3 August 2024 (UTC)[reply]
Thank you, I moved it there. Polygnotus (talk) 15:09, 3 August 2024 (UTC)[reply]

August 4

[edit]

Karnaugh map/gates

[edit]

As of now, is the 'or' gate better at handling electricity vs the 'and' gate?Afrazer123 (talk) 01:29, 4 August 2024 (UTC)[reply]

That will depend on the implementation, and what electrical state represents the 0 or 1. And it also depends on what you mean by "better". (faster, less energy wasted, smaller, least noise, least sensitive to noise, fan out, tolerance of power supply variation, cheaper, higher yield). Graeme Bartlett (talk) 10:47, 4 August 2024 (UTC)[reply]
Yes. The Karnaugh map is useful for showing logical relations between Boolean data types that take only values "1" (true) or "0" (false). Elementary Logic gate functions such as AND, OR, NAND, NOR, EXOR, etc. can be mapped, also combinations of connected gates if they are not too complicated. However Boolean data is abstract and the "1" and "0" need not always correspond to electric voltages. Karnaugh maps are equally applicable to fluid logic that uses water instead of electricity. For example a fluid OR gate is simply two pipes being merged. Philvoids (talk) 17:15, 4 August 2024 (UTC)[reply]
"better": less energy wasted, higher yield. Afrazer123 (talk) 05:52, 5 August 2024 (UTC)[reply]
CMOS (Complementary metal–oxide–semiconductor) logic devices have low static power consumption and do not produce as much waste heat as other forms of logic, like NMOS logic or Transistor–transistor logic (TTL), which normally have some standing current even when not changing state. Since one transistor of the MOSFET pair is always off, the series combination draws significant power only momentarily during switching between on and off states. There is no significant difference between power consumptions of the logic functions AND, OR, etc. The current drawn from the supply increases with increasing rate of data changes and is mainly due to charging and discharging the output capacitance. Philvoids (talk) 13:14, 5 August 2024 (UTC)[reply]
Thanks, I read about the clock rate or clock speed. I think it adds to the logic your reply. Afrazer123 (talk) 21:20, 6 August 2024 (UTC)[reply]
For actual numbers, old digital circuits that I used back in the 70s implemented both and and or with components. The drop is 0.3v pretty much any way you do it for both an or and an and gate. You are either dropping 0.3v across a diode or 0.3v across a transistor. I doubt any modern circuits have that much drop and I'm certain it is still very similar between diodes and transistors. 12.116.29.106 (talk) 12:20, 6 August 2024 (UTC)[reply]
Modern CMOS gates don't have diodes, nor do the MOS transistors have saturation voltage drops of the sort you're talking about. Dicklyon (talk) 03:53, 8 August 2024 (UTC)[reply]
"As of now" means CMOS, one would presume. The "elementary" gates are inverting: NAND and NOR. One has a marginally better energy per operation than the other, but not so much that you'd worry about it. And it depends on your logic conventions, which you can change in midstream if that helps. Back in the NMOS days, with positive logic (higher voltage representing logic 1), the NOR gate had a signficantly better energy per operation than the NAND gate, due to the use of N-type switches to ground and passive pullups, with switches being in series for NAND and parallel for NOR. And both were better than PMOS gates, due to the higher mobility of electrons compared to holes. But CMOS is more nearly symmetric (at least in the most typical logic gate circuits). I think the one with series N-type and parallel P-type devices is a bit better (that's a NAND for positive logic); but I wouldn't swear to it. Choosing NAND vs NOR is not a big deal compared to using AOI (AND-OR-invert) gates and optimizations at other levels. One such other technique is the use of dynamic logic, which gets more complicated to reason about, but still probably the gates with parallel switches are a bit more energy efficient than the ones with series switches. But other considerations dominate. And I haven't seen anyone use Karnaugh maps in the last 4 decades; are they still teaching those? Dicklyon (talk) 03:53, 8 August 2024 (UTC)[reply]
By the way, the Apollo Guidance Computer#Logic hardware used only one type of small-scale chip: a dual 3-input NOR. Dicklyon (talk) 04:03, 8 August 2024 (UTC)[reply]

August 5

[edit]

Downloading MediaWiki for home use

[edit]

I usually use an LG Gram 1 TB SSD laptop with 32 GB RAM. I've got about 600 MB free. I would like to be able to create articles on my own PC instead of using my personal userspace. I haven't gotten any response at Talk:MediaWiki, so I'm asking here. I have always created my articles in my userspace, but have recently experienced harassment and stalking for doing so, and I'm tired of it.

Can MediaWiki be downloaded for personal use at home, with no one else accessing it? If so, what would be the requirements to get it functioning properly? Would I need to download other software, or have a huge hard drive? I guess I'm hoping for a word processor type program that works like editing here.

If it won't work in that way, is there another software program that uses the same wikimarkup we use here? I'd like to be able to create content on my PC, move it to userspace, maybe then to draftspace, and finally to mainspace. -- Valjean (talk) (PING me) 02:22, 5 August 2024 (UTC)[reply]

You can download MediaWiki software yourself, as per Manual:Installation requirements. You will require both a database and a way to serve the webpages to the user, however, as well as PHP. Doing this yourself would require a separate server or machine, although you can use a webhost and just have them install the required dependencies.
Actual storage and memory requirements are quite low, so storage wouldn't be a terrible issue, but depending on how much you would use it, that can fill up relatively quickly.
Alternatively, there are several wiki softwares that aren't all that great for public use, but are good for what you want to do (personal, internal use). Something like wikijs or dokuwiki would be better suited for this. SmittenGalaxy | talk! 06:41, 5 August 2024 (UTC)[reply]
It sounds a bit complicated for this old man. Is there anything simpler and similar to a word processor program like Microsoft Word (and I'm old enough to have used WordPerfect and directly edited its code) that uses our wiki markup? It's okay if there are red links because I wouldn't be hosting all of Wikipedia. -- Valjean (talk) (PING me) 14:54, 5 August 2024 (UTC)[reply]
There is Extension:Word2MedaWiki that can take Microsoft Word and translate it to MediaWiki markup, although it is quite old and unmaintained, and as such I don't believe works on newer 64-bit versions of Word. Microsoft did release this addon for Word 2007 and 2010 (and 2013 with registry editing).
Aside from those, LibreOffice and OpenOffice (stated below as well) are standalone editors that can save directly as MediaWiki. See Help:WordToWiki as well. SmittenGalaxy | talk! 21:51, 5 August 2024 (UTC)[reply]
OpenOffice has a wiki extension so you can write articles in a word processor and save them in wiki markup. I personally do not feel that it procudes optimal markup, but it works. 75.136.148.8 (talk) 18:41, 5 August 2024 (UTC)[reply]
  • Yes, you can do this. I've been doing it for years: on my own servers, on my laptop (often on client sites) and also internet hosted MediaWikis, so that I can access them elsewhere. They're all fairly easy.
One way to do this is with a hosting company (or the free tier on AWS) that offers a 'one click install' of MediaWiki. This is very simple.
However installing complex software on a public-accessible website always needs care and competence. Even if you're just locking it down as an extranet, you still need to lock it carefully. Andy Dingley (talk) 23:18, 5 August 2024 (UTC)[reply]
Or else you do it the classic and well-documented route of installing a Linux (or Xampp under Windows), then Apache web server, then PHP, then MediaWiki, then some MediaWiki extensions, then the Wikipedia content (mostly some templates) needed to emulate the Wikipedia experience. Because it's not so simply bundled, it's the Wikipedia templates that might take the most time to do. You can also install Lua (not all installs do this as standard) which many Wikipedia templates use instead of MediaWiki template code (which is hateful stuff anyway).
I use this every day. It's my basic desktop organisation tool. I also used to use it for writing articles for here, back when that was still worth doing. Andy Dingley (talk) 22:32, 5 August 2024 (UTC)[reply]
I think this highlights a key point not really discussed until now. If you're hoping to develop content for en.wikipedia and you want to be able to actually preview locally what you've developed, it's quite likely it's not just a basic wiki install you need but key templates as well. I mean even if you don't care about infoboxes and some stuff so can ignore these, you're probably using templates for referencing and maybe some other formatting things. A quick look at one example of what I guess is a sandbox [3] shows plenty of templates e.g. for referencing, block quotes, and other things. Note also that unless you have a local mirror of all content, or some other more complicated set-up, all interwiki links will generally be red so it might be difficult to notice if you've made a mistake. I'm sure there are ways to set it up to just obtain the templates from en.wikipedia but I suspect this is complicated and you might need some caching setup or API access or risk excessively downloads from the web frontend that server admins aren't happy. Possibly a better option might be to just write and store your content locally, with something capable of highlighting wikisyntax and/or providing shortcuts if that's what you want, and then preview online. This does mean you need an internet connection whenever you preview. (In theory you could make this fairly automated so you have an editing syntax and are able to save locally, except when you preview it uses en.wikipedia, but I'm not sure if there's an easy way to set that up.) Nil Einne (talk) 00:16, 6 August 2024 (UTC)[reply]
Ideally, volunteer editors (all of us!) should be allowed to use their "personal userspace" for article creation:
"If you would like to draft a new article, Help:Userspace draft provides a standard template and useful guidance to help you create a draft in your userspace, and the Article Wizard can walk you through all stages of creating an article with the option to save as a userspace draft too. You can use the template {{userspace draft}} to tag a userspace draft if it is not automatically done for you."(source)
Does it come with an RfD tag already prepended so nobody else has to slap it on the moment you publish the article? 75.136.148.8 (talk) 11:52, 7 August 2024 (UTC)[reply]
Those are the rules here, after all, but some don't approve of that practice when it's a topic they don't want to see here, as I have found out. If it's uncontroversial content, then they don't cause problems. Hmmm.... -- Valjean (talk) (PING me) 18:40, 6 August 2024 (UTC)[reply]
Installing a whole MediaWiki installation may be overkill if the primary use case is working on article drafts. There are a variety of plain text editors with extensions/plugins for highlighting and formatting MediaWiki markup. This also reduces the risk of losing your work if your web browser crashes or drops its cache. ClaudineChionh (she/her · talk · contribs · email) 12:06, 7 August 2024 (UTC)[reply]

August 7

[edit]

Single versus Multiple Exit Points in a Function

[edit]

When I was in school back in the 90s, we were taught that a function should have only one exit point. Do they still teach this? I'm asking because I'm coming across a lot of code when doing code reviews where the developer has multiple exit points and I'm wondering if I should ask them to change their code to have one exit point or let it slide. For example, I often see code like this:

        private static bool IsBeatle1(string name)
        {
            if (name == "Paul") 
            {
                return true;
            }
            if (name == "John")
            {
                return true;
            }
            if (name == "George")
            {
                return true;
            }
            if (name == "Ringo")
            {
                return true;
            }
            return false;
        }

Personally, this is how I would have written this code:

        static bool IsBeatle2(string name)
        {
            bool isBeatle = false;
            if (name == "Paul")
            {
                isBeatle = true;
            }
            else if (name == "John")
            {
                isBeatle = true;
            }
            else if (name == "George")
            {
                isBeatle = true;
            }
            else if (name == "Ringo")
            {
                isBeatle = true;
            }
            return isBeatle;
        }

So, my question is two fold:

  1. Do they still teach in school that a function should have a single exit point?
  2. When doing code reviews, should I ask the developer to rewrite their code to have one single exit point? Yes, I realize that this second question is a value judgement but I'm OK with hearing other people's opinions.

Pealarther (talk) 11:21, 7 August 2024 (UTC)[reply]

If there was only one school with only one instructor, your answer could be "yes" or "no." However, there are millions of schools with millions of instructors. So, the only correct answer is "both." Yielding functions and scripting languages have changed what is considered optimal when writing functions. So, it comes down to what the function does, what language is being used, and what the instructor feels like teaching. 75.136.148.8 (talk) 11:49, 7 August 2024 (UTC)[reply]
  • Many things taught in the '90s, and especially the '80s, are now realised to be unrealistic.
There is no reason why functions should only have one exit point. What's important is that some boundary exists somewhere where you can make absolute statements about what happens when crossing that boundary. Such boundaries are commonly functions, but it's broader than that too. In this case, we can define a contract, 'Leaving this function will always return a Boolean, set correctly for isBeatleness.' That's sufficient. To then mash that into this type of simplistic 'Only call return once, even within a trivial function' is pointless and wasteful.
You might also look at 'Pythonic' code, the idiomatic style of coding optimised for use in Python. This raises exceptions quite generously, see Python syntax and semantics#Exceptions. The boundary here is outside the function, but instead the scope of the try...except block. In Pythonic code, the exception handler that catches the exception might be a very long way away. Andy Dingley (talk) 13:58, 7 August 2024 (UTC)[reply]
Yes, it was accepted wisdom (at least in academic teaching of programming) in the 1980s, and Pascal (the main teaching language in a lot of academic settings) effectively enforced it (at least in the academic versions people taught - I rather think Turbo Pascal, which was always more pragmatic, will not enforce this). But it leads to some horrible patterns:
  1. checking inputs and other preconditions are acceptable leads to deep nested ifs, with the "core" of the function many deep.
  2. "result" accumulation - especially where "break" is also prohibited (with the same reasoning), where the function has "finished" its calculation, but has to set a result variable, which then trickles down to the eventual real return at the end of the function. This (and the break prohibition) leads to fragile "are we done yet" booleans.
So the restriction was an attempt to avoid bad code, but in doing so produced lots of different kinds of bad, unreadable, fragile code. So it's a daft restriction.
I've no idea what academics teach now, and frankly what universities (often in toy or abstract cases) do is seldom what industry does. So let's look at what industry does:
  • Code Complete reads "Minimize the number of returns in each routine. It's harder to understand a routine when, reading it at the bottom, you're unaware of the possibility that it returned some-where above. For that reason, use returns judiciously—only when they improve readability."
  • Neither the CoreCPPGuidelines nor Google's C++ styleguide seems to say anything on the topic
  • Notable codebases like Chrome, the Linux Kernel, PDF.js, IdTech3, MySQL, LLVM, and gcc all frequently use multiple return paths.
That doesn't mean "just return willy-nilly wherever", as that can be as bad - Code Complete gives smart advice. But it's a bad rule, which won't produce better code in real circumstances, and will frequently produce worse code. "Write good code" can't be boiled down to such simple proscriptions. -- Finlay McWalter··–·Talk 14:13, 7 August 2024 (UTC)[reply]
I tend to agree with the OP. However, the example of multiple exits he gives is not that bad because they are all right together. It would be worse practice to have four exits randomly spread out in a routine. Bubba73 You talkin' to me? 04:08, 8 August 2024 (UTC)[reply]
The underlying rationale for the directive to have a single exit is to make it easier to ascertain that a required relationship between the arguments and the return value holds, as well as (for functions that may have side effects) that a required postcondition holds – possibly involving the return value. If the text of the body of a function fits on a single screen, forcing a single exit will usually make the code less readable. As long as it is easy to find all exits – much easier with on-line editors than with printouts of code on punch cards as was common before the eighties – the directive no longer fulfills a clear purpose.  --Lambiam 08:14, 8 August 2024 (UTC)[reply]

How are one-time passwords secure?

[edit]

To log into my Mailchimp account, I need a password plus a one-time code I either read off the Google Authenticator app on my Samsung tablet, or off the iCloud keychain. The two sources always give the same code, and to set them up, I had to enter a 16-letter code. My question is: how does any of this increase security? To get the one-time code, all a hacker needs is the 16-letter code used, and they're good to go. It just seems like a second password but more complicated. I thought the idea of one-time codes was that it would be something I know (password) and something I have (my tablet). But in fact the something I have is only useful because of the 16-letter code (something else I know). Amisom (talk) 15:48, 7 August 2024 (UTC)[reply]

If you know the secret key (the code you started with), the current time, and the algorithm, you can produce the OTP key at any point in time. 75.136.148.8 (talk) 17:21, 7 August 2024 (UTC)[reply]
Or indeed, as I said, all you need is the secret key and a widely available app like Google Authenticator. So my question is how and why that is more secure than a password alone. Amisom (talk) 17:23, 7 August 2024 (UTC)[reply]
The issue is if your communication is being intercepted, someone is looking over your shoulder, or a bug in the browser state means the text you entered (which should be forgotten immediately) is retained in memory, and a wrongdoer can recover it later. If you were sending a shared secret (e.g. a password), now the enemy has your password. If all you enter is the OTP, which expires in a minute or two, the enemy has only seconds to use it. As the OTP is generated from the 80-bit shared secret with a one-way function (in this case, a cryptographic hash function), they can't reverse OTP to recreate the 80-bit secret. The 80-bit shared secret key should not be your regular password, nor derived from it. Typically, when setting up a HOTP entry in Authenticator, the service (e.g. Mailchimp) should generate an 80 bit random key and usually shows this on screen with a QR code (for Google Authenticator to read). After that, the 80-bit shared secret is never passed between the two parties. -- Finlay McWalter··–·Talk 18:02, 7 August 2024 (UTC)[reply]
Technically, as the concern mentions, if I had thousands of computers all attempting to authenticate at the same time, I could have each one attempt thousands of possible OTP keys based on trying every possible original seed value used to set up the OTP. If one works, I can continue using it without the extra overhead of trying millions of combinations. But, even if only 16 hex values were used in the random initial seed, there would be over 1,000,000,000,000 possible values to try. As mentioned above, you can't intercept this as you can with a password. It is not transmitted anywhere. The user never types it into anything after setting up the OTP. But, the concern is not completely without merit. It is possible that someone could randomly pick out the original value used to set up the whole thing and then have their own copy of it to use. It comes down to the old analogy of you can spend billions to build a system to work out a person's OTP and hack into their bank account or you can spend $5 on a good hammer and force them to give you their phone so you can use it to log in easily. 75.136.148.8 (talk) 19:53, 7 August 2024 (UTC)[reply]
There are 1616 different hexadecimal strings of length 16, which is more than 1.8×1019. This is a whole lot more than 1,000,000,000,000.  --Lambiam 21:51, 7 August 2024 (UTC)[reply]
The comment above that mentions an 80-bit shared secret. Assuming 8 bits per character, that is 10 characters, not 16. Regardless, it is correct to state that it is not likely someone will brute force an OTP secret easily. 12.116.29.106 (talk) 12:40, 8 August 2024 (UTC)[reply]

August 8

[edit]

A new test for comparing human intelligence with Artificial intelligence, after the Turing test has apparently been broken.

[edit]

1. Will AI discover Newton's law of universal gravitation (along with Newton's laws of motion), if all what we allow AI to know, is only what all physisists (including Copernicus and Kepler) had already known before Newton found his laws?

2. Will AI discover the Einstein field equations, if all what we allow AI to know, is only what all physicists had already known before Einstein found his field equations?

3. Will AI discover Gödel's incompleteness theorems, if all what we allow AI to know, is only what all mathematicians had already known before Gödel found his incompleteness theorems?

4. Will AI discover Cantor's theorem (along with ZF axioms), if all what we allow AI to know, is only what all mathematicians had already known before Cantor found his theorem?

5. Will AI discover the Pythagorean theorem (along with Euclidean axioms), if all what we allow AI to know, is only what all mathematicians had already known before pythagoras found his theorem?

If the answer to these questions is negative (as I guess), then may re-dicovering those theorems by any given intelligent system - be suggested as a better sufficient condition for considering that system as having human intelligence, after the Turing test has apparently been broken?

HOTmag (talk) 18:08, 8 August 2024 (UTC)[reply]

Most humans alive could not solve those tests, yet we consider them intelligent. Aren't those tests reductive? Isn't it like testing intelligence by chess playing? We consider some chess machines very good at chess, but not "intelligent". --Error (talk) 18:31, 8 August 2024 (UTC)[reply]
According to my suggestion, the ability to solve the problems I've suggested, will not be considered as a necessary condition, but only as a sufficient condition. HOTmag (talk) 18:39, 8 August 2024 (UTC)[reply]