Editing 1685: Patch

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 8: Line 8:
  
 
==Explanation==
 
==Explanation==
{{w|Adobe Photoshop}} is a commonly used application for image manipulation. One of its features is the Patch tool, which allows the user to overwrite parts of the image, replacing them with a copy of another area of the same image. It is often used for “patching up” photographs by overwriting scratches or other visible damage to the photo. Another of Photoshop’s features is “content-aware fill”, which could also be described as “content-aware inpainting”. It works similarly to the Patch tool, but automatically generates a replacement texture from the area surrounding the deleted part instead of copying a user-specified area exactly.
 
  
{{w|GNU}} {{w|Patch (Unix)|patch}} is a program that replaces only parts of code with an updated version, without requiring the user to download the entire source code. Here, it appears the author was told to “patch” the code but used Photoshop to do this instead of GNU patch, with devastating results.{{citation needed}} Although the title text suggests that if you did this enough times the code would eventually compile, this would never happen. In fact, Photoshop could only edit an image of the text and not the text itself. However, it could work if optical character recognition (OCR) were integrated into the workflow as well.
 
  
The comic blurs the difference between {{w|text_file|text}} (in which letters and symbols represent discrete values, such as 65 being the number for the letter A in the ASCII encoding standard, and it's relatively easy for a program compiler to interpret combinations of these values as keywords and other programming constructs) and {{w|Raster_graphics|graphics}} (where the letters and symbols in the comic are actually represented by a pattern of colored dots), playing with the idea that the ''patch'' metaphor can be used on both (although with different meanings). There are common and straightforward processes for converting text information to images, such as printing, which can convert text to a graphics format very faithfully. The reverse, however, requires the use of {{w|optical character recognition}} (OCR), which attempts to figure out which letter or symbol certain patterns of dots "look like". OCR could be effective in converting some of the image in the comic back to usable text; however, it would fail on some of those patterns that have been mangled and don't look like any existing characters or symbols. A compiler can only operate on text data, so converting the graphic back into text would be a requirement to even begin to attempt to compile it, a step omitted in the title text.
+
{{w|Adobe Photoshop}} is a commonly used software for image manipulation. One of its features is "content-aware inpainting", which allows the user to delete parts of the image and seamlessly replacing the deleted sections with "patches" of texture from other parts of the image.  
  
The code appears to be written in {{w|Python_(programming_language)|Python}}, a programming language often referred to in xkcd, such as in [[353: Python]]. A few of the function names that can be recognized are "isPrime" and "quicksort", both elementary programming algorithms. It was also apparently originally edited using a Python-aware programming text editor, which is able to use different colors for different programming elements. For example, it appears to use red for keywords, blue for variables, and black for other elements; however, because of the mangling from the use of the wrong patching program, that doesn't appear to be consistent. Since the patching replaced graphical elements rather than whole characters, there are examples of symbols that are combinations of two different characters, and when the original two characters were rendered in different colors the resulting non-character could be in two colors, or the resulting "word" might be rendered in multiple colors.
+
The {{w|GNU}} {{w|Patch (Unix)|patch}} is a software program that replaces only parts of the code with an updated version, without requiring the user to download the entire source code. Here, it appears the author was told to "patch" the code, but used Photoshop to do this instead of GNU patch, with devastating results. Although the title text suggest that if you did this enough times the code would eventually compile, this would never happen... In fact, Photoshop could only edit an image of the text and not the text itself.
  
The comic brings to attention the high rate of Adobe Photoshop piracy. GNU Patch is available for free, even [http://gnuwin32.sourceforge.net/packages/patch.htm for Windows], and Mac OS X. So the comic implies that Adobe Photoshop, a subscription to which costs $20/month, is more available than GNU patch. According to [http://blog.epicedits.com/2008/03/28/60-of-photoshop-users-are-pirates/ this poll], 58% of Photoshop copies were pirated.
+
The code appears to be written in {{w|Python_(programming_language)|Python}}, a programming language often referred to in xkcd.. A few of the function names that can be recognized are "isPrime" and "quicksort", both commonly used in solving programming contest problems.
  
The title text also explains that the patch used the content-aware inpainting to fill in all the wasted whitespace in the code. In most programming languages, whitespace is necessary to separate words, so this would combine words that shouldn’t be combined and create invalid code. Since the code in the image is Python, the code will be messed up even more, because Python uses whitespace as a part of its programming syntax. For example, statements are separated by newlines instead of by semicolons (;), and indentation is used instead of brackets to determine the scope of each section of code.
+
The title text also explains that patch used the content-aware inpainting to fill in all the wasted whitespace in the code. In Python, whitespaces are used as a part of programming syntax (for example, new line of code are used instead of semicolon (;), and indents are used instead of curly brackets.
 
 
The original code was likely as follows:
 
 
 
<font color="red">import</font> re
 
<font color="red">def<font color="purple"> isPrime</font></font>(n):
 
<font color="red">if </font>n<font color="red"><=</font><font color="#44A1FF">1</font>:
 
<font color="red">return</font> <font color="#44A1FF">False</font>
 
<font color="red">for</font> i <font color="red">in <font color="#44A1FF">range</font></font>(<font color="#44A1FF">2</font>, <font color="#44A1FF">int</font>(n<font color="red">**</font><font color="#44A1FF">0.5</font>)<font color="red">+</font><font color="#44A1FF">1</font>):
 
<font color="red">if</font> n<font color="red">%</font>i<font color="red">==<font color="#44A1FF">0</font></font>:
 
<font color="red">return<font color="#44A1FF"> False</font></font>
 
<font color="red">return <font color="#44A1FF">True</font></font>
 
<font color="red">def <font color="purple">isPrimeRegex</font></font>(n):
 
<font color="red">if</font> re.match(<font color="red">r</font><font color="blue">'</font><font color="#44A1FF">^</font><font color="blue">1</font><font color="red">?<font color="#44A1FF">$</font>|<font color="#44A1FF">^</font><font color="blue">(11</font>+?<font color="blue">)</font><font color="green">\1+</font><font color="#44A1FF">$</font></font><font color="blue">'</font>, <font color="blue">'1'</font><font color="red">*</font>n):
 
<font color="red">return <font color="#44A1FF">False</font>
 
<font color="red">return<font color="#44A1FF"> True</font></font></font>
 
<font color="red">def<font color="purple"> quicksort</font></font>(a):
 
<font color="red">if <font color="#44A1FF">len</font></font>(a) <font color="red">< <font color="#44A1FF">2</font></font>:
 
<font color="red">return </font>a
 
pivot<font color="red">=</font>a[<font color="#44A1FF">0</font>]
 
l<font color="red">=</font>[i<font color="red"> for</font> i <font color="red">in</font> a <font color="red">if</font> i<font color="red"><</font>pivot]
 
r<font color="red">=</font>[i<font color="red"> for</font> i <font color="red">in</font> a <font color="red">if</font> i<font color="red">></font>pivot]
 
mid<font color="red">=</font>[pivot]<font color="red">*</font>(<font color="#44A1FF">len</font>(a)<font color="red">-</font>(<font color="#44A1FF">len</font>(l)<font color="red">+</font><font color="#44A1FF">len</font>(r)))
 
<font color="red">return </font>quicksort(l)<font color="red">+</font>mid<font color="red">+</font>quicksort(r)
 
 
 
isPrime and quicksort are standard python implementations of simple algorithms (although you would not generally write a sorting algorithm in python as there are built-in algorithms available).  isPrimeRegex uses the [https://docs.python.org/library/re.html re module] to detect if a number is prime by seeing if a string containing that many 1s can be matched to 2 or more copies of some string containing at least 2 1s.
 
 
 
The comic two comics back [[1683: Digital Data]], also related to turning digital data into bad copies. Less than a month before quicksort was mentioned in [[1667: Algorithms]], and a month before that another "easy" solution to a programming problem was released in [[1654: Universal Install Script]].
 
 
 
Using a Photoshop tool for a task it is not intended for was also used in [[1784: Bad Map Projection: Liquid Resize]], where [https://helpx.adobe.com/photoshop/using/content-aware-scaling.html Photoshop's content-aware resizing tool] was a very questionable choice to use for a Map Projection.
 
  
 
==Transcript==
 
==Transcript==
:[The panel displays part of a code, in five different colors (red, purple, light blue, blue, and green) as well as normal black text, which due to image editing is difficult to read. The first and last lines are partly obscured by the frame of the panel. Here below is an attempt to transcribe the code, using the sign "¤" for anything not easily transcribed. Feel free to add other signs instead of these that look more like the one in the image (and also improve the attempted transcription if possible).]
+
:[The panel displays part of a code, in four different colors (red, light blue, green and purple) as well as normal black text, which due to image editing is difficult to read. The first and last line are partly obscured by the frame of the panel. Here below is an attempt to transcribe the code, using the sign "¤" for anything not easily transcribed. Feel free to add other signs instead of these that looks more like the one in the image (and also improve the attempted transcription if possible).]
<font color="red">impoɞt</font> <font color="purple">ne</font>
+
:<font color="red">impo¤l <font color="purple">me
<font color="red">doo</font><font color="purple">PisPʂnme</font>(n):
+
:<font color="red">doo<font color="purple">PisPS¤me</font></font></font></font>(n):
<font color="red"></font>(<font color="purple">¤</font>n<font color="red"><</font>n,<font color="#44A1FF">1</font>:
+
:::<font color="red">r</font>(<font color="purple">¤</font>n<font color="red"><</font>n,<font color="light blue">1</font>:
<font color="red">retɐrn</font> <font color="#44A1FF">F</font>(<font color="#44A1FF">ise</font>
+
:::::<font color="red">retern</font> <font color="light blue">F</font>(<font color="light blue">ise</font>
<font color="red">for</font> i <font color="red">ir</font><font color="#44A1FF">arar𝞬e</font>(<font color="#44A1FF">2</font>, <font color="#44A1FF">ninߙ</font> <font color="red">*</font>n<font color="red">**</font>n<font color="red">+</font><font color="#44A1FF">5</font>)<font color="red">+</font><font color="#44A1FF">5</font>):
+
:::<font color="red">for</font> i <font color="red">ir<font color="light blue">ararre</font></font>(<font color="light blue">2</font>, <font color="light blue">nint</font> <font color="red">*</font>n<font color="red">**</font>n<font color="red">+</font><font color="light blue">5</font>)<font color="red">+</font><font color="light blue">5</font>):
<font color="red">if</font> n i<font color="red">==</font><font color="#44A1FF">0</font>
+
:::::<font color="red">if</font> n i<font color="red">==<font color="light blue">0</font></font>
<font color="red">re力¤𝑟nr</font><font color="#44A1FF">₅ɵlsel</font>:
+
:::::::<font color="red">ret¤¤nrs<font color="light blue">elsel</font></font>:
<font color="red">re</font><font color="purple">𝗿</font><font color="red">⃓rn </font><font color="#44A1FF">True</font>
+
:::<font color="red">re¤ irn <font color="light blue">True</font></font>
<font color="red">defe</font><font color="purple">𝟧isPrimϵieg˓x</font>(c<font color="purple">x</font>
+
:<font color="red">defe<font color="purple">sisPrimcieg ¤x</font></font>(c<font color="purple">x</font>
<font color="red">if</font> <font color="purple">g</font>ƨ<font color="purple">¤i</font>natc<font color="purple">x</font>(<font color="red">r</font>'<font color="#44A1FF">^</font><font color="blue">(1</font><font color="red">?| ?.</font><font color="blue">1</font><font color="red">+?</font><font color="blue">)</font><font color="lime">\+</font><font color="blue">)</font><font color="#44A1FF">$</font>'<font color="red">*</font>n <font color="blue">⎞1'</font><font color="red">*</font>n):
+
:::<font color="red">if</font> <font color="purple">g</font>e<font color="purple">¤i</font>natc<font color="purple">x</font>(<font color="red">r</font>'<font color="light blue">^<font color="blue">(1<font color="red">?| ?.<font color="blue">1<font color="red">+?<font color="blue">)<font color="gree">\+<font color="blue">)<font color="light blue">$</font></font></font></font></font></font></font></font></font>'<font color="red">*</font>n <font color="blue">)1'<font color="red">*</font></font>n):
<font color="red">rerɹrn </font><font color="#44A1FF">Fa</font><font color="blue">(</font><font color="#44A1FF"> e</font>
+
:::::<font color="red">rerjrn <font color="light blue">Fa<font color="blue">(</font> e</font></font>
<font color="red">ιetu⃓</font><font color="purple">nr</font><font color="#44A1FF">TrꙆ</font>
+
:::<font color="red">Letyl<font color="purple">nr<font color="light blue">Trl</font></font></font>
<font color="red">dq</font><font color="purple">⃓ q⃓soʀsor</font><font color="#44A1FF">η</font>(a :
+
:<font color="red">dq<font color="purple">l qlsorsor<font color="light blue">n</font></font></font>(a :
<font color="red">if </font><font color="#44A1FF">¤n</font>(a <font color="red">< </font><font color="#44A1FF">2</font>:
+
:::<font color="red">if <font color="light blue">¤n</font></font>(a <font color="red">< <font color="light blue">2</font></font>:
<font color="red">eteturn </font>a
+
:::::<font color="red">eteturn </font>a
pi<font color="red">=꞊ᵣ f</font>a[<font color="#44A1FF">0</font>]
+
:::pi<font color="red">= =r f</font>a[<font color="light blue">0</font>]
l<font color="red">=</font>pi<font color="red">=for</font> j <font color="red">ın</font> a i<font color="red"><</font> i<font color="red"><</font>pi<font color="red"><</font>(t]<small>(</small>)
+
:::l<font color="red">=</font>pi<font color="red">=for</font> j <font color="red">ln</font> a i<font color="red"><</font> i<font color="red"><</font>pi<font color="red"><</font>(t]<small>(</small>)
r<font color="red">=</font>[ı<font color="red">=for 𝟋 in</font> a) <font color="red">r</font> i<font color="red">></font>viviv]<small>(</small>vo)
+
:::r<font color="red">=</font>[l<font color="red">=for f in</font> a) <font color="red">r</font> i<font color="red">></font>viviv]<small>(</small>vo)
mid<font color="red">=</font>[pi[<font color="red">*</font>t]<font color="red">*</font>(<font color="#44A1FF">l</font><font color="red">*</font>t<font color="#44A1FF">ˌ</font>(a)<font color="red">-</font>(<font color="#44A1FF">⟘en</font>pᚆ<font color="#44A1FF">enlen</font>(c)))
+
:::mid<font color="red">=</font>[pi[<font color="red">*</font>t]<font color="red">*</font>(<font color="light blue">l</font><font color="red">*</font>t<font color="light blue">,</font>(a)<font color="red">-</font>(<font color="light blue">len</font>pi<font color="light blue">enlen</font>(c)))
<font color="red">r¤lrurrr</font>ikıcksckt(l) <font color="red">+</font> r ¤ ¤quickrprt(r)
+
:::<font color="red">r¤lrurrr</font>iklcksckt(l) <font color="red">+</font> r ¤ ¤quickrort(r)
  
 
:[Caption below the panel:]
 
:[Caption below the panel:]
Line 76: Line 45:
  
 
{{comic discussion}}
 
{{comic discussion}}
 +
 
[[Category:Comics with color]]
 
[[Category:Comics with color]]
 
[[Category:Protip]]
 
[[Category:Protip]]
 
[[Category:Programming]]
 
[[Category:Programming]]
[[Category:Photography]]
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)