Event Headline
في هذا القسم ، أريد أن أوضح أنه يمكنك إجراء اختبار بسيط ، مثل startWith ("A") و
استخدم فكرة AND و OR لدمجها مع اختبارات أخرى لتصنيفها
معا اختبار أكثر تعقيدا. وهذا ما يسمى المنطق المنطقي. هكذا الطريق هذا
هو العمل ، هو ، في الرمز ، مفهوم AND هو ، رمز لتلك الاثنين
تعمل علامات الضم معًا (&&). والرمز لـ OR هو شريطان عموديان (||) ،
ضع سويا. لذلك اسمحوا لي أن أريك ما يبدو. لذلك هنا بعض الرموز. و
يحتوي الاختبار الأول على ما إذا كان الاسم يبدأ بـ "A" ، تمامًا كما رأينا من قبل ،
وهذا الاختبار ، هو كامل وظيفي. بحيث لا يتم تغيير بواسطة
مضيفا فكرة المنطق المنطقي. لذلك بالنسبة للمنطق منطقية ، ما نقوم به هو أننا نأخذ ذلك
اختبار ونحن نتابع ذلك مع اثنين من علامات الضجر. لذلك سوف نطق ذلك باسم ، و. و
ثم يتبعه اختبار ثانٍ. الاختبار الثاني هو أيضا كاملة ويجعل
الشعور من تلقاء نفسها. لذلك ، ما يفعله هذا هو أنه يتطلب اختبارين فقط ويضعهما
معا ، وتقول ، حسنا. ولكي يكون هذا الاختبار الشامل صحيحًا ، فإن كلاهما
الأجزاء الفرعية يجب أن تكون صحيحة. إذاً المكونات ، حسناً ، هنا ، سوف أركض
ذلك. فما يقوله هذا هو ، الأسماء التي تبدأ بـ "A". هذا يجب أن يكون صحيحا. والاسم
يجب أن ينتهي بـ "y". لذلك إذا قمت بتشغيله ، فإننا نحصل على هذا ، كما تعلمون ، قائمة أقصر بقليل من
الأسماء التي تبدأ بـ "A" وتنتهي بـ "y". كما لو كنت قلت انها لديها اثنين
الاختبارات ، كل منها كاملة. لقد انضموا إلى AND أو ، أو كما سنرى
دقيقة. ثم أخيرًا ما زالت هناك مجموعة واحدة من الأقواس ، أقصى اليسار
الأقواس والأكثر حقًا ، والأقواس الأكثر حقًا ، حول الشيء بأكمله. وبالتالي
سأفعل مجموعة من الأمثلة ، مثل هذا. زوجين آخرين ، شيء واحد آخر للإشارة
حول هذا ، في هذه الحالة ما حدث هو ، اختبار نوع من طويلة ، أليس كذلك؟ لدي
هذا كله يبدأ مع جزء ، وعلامة الضم ، لذلك إذا فعلت كل شيء في سطر واحد ،
In this section, I wanna show you can take a simple test, like startsWith("A"), and
use, the notion of AND, and OR, to combine it with other tests to sort of put
together a more complicated test. So this is called Boolean logic. So the way this
is gonna work, is, in code, the notion of AND is the, the symbol for that two
ampersands run together (&&). And the, the symbol for OR is two vertical bars (||),
put together. So let me show you what that looks like. So here's some code. And it
has, the first test just says if the name starts with "A", just as we've seen before,
and that test is, it's complete and functional. So that is not changed by
adding the notion of Boolean logic. So for Boolean logic, what we do is we take that
test and we follow it with two ampersands. So you would pronounce that as, AND. And
then it's followed by a second test. The second test is also complete and makes
sense on its own. So, what this does is it just takes two tests and it puts them
together, and it says, well. For this overall if-test to be true, both of these
subparts have to be true. So the components are, well here, I'll, I'll run
it. So what this says is, names that begin with "A". That has to be true. And the name
has to end with "y". So if I run it, we just get this, you know, kinda shorter list of
names that begin with "A" and end with "y". Syntactically like I said it has the two
tests, each of which is complete. They're joined with AND or, OR as we'll see in
a minute. And then finally there is still this one set of parentheses, a left most
parentheses and a right most, a right most parenthesis, around the entire thing. So
I'll do a bunch of examples, like this. A couple other, one other thing to point out
about this, in this case what happened is, the test is kind of long, right? I have
this whole startsWith part, and the ampersand, so if I did it all on one line,
يحصل قليلا ، قليلا طويلة. إذن ما حدث في هذه الحالة هو أنا ، لقد أصبت
العودة بعد علامة الضم. ذهبت إلى هنا وضربت شريط الفضاء ، للحصول على
صف هنا ونوع من الخط. لذلك كتبت الاختبار الثاني على السطر الثاني.
هذا اختياري ولكن يمكنك القيام بذلك. وضع في الفضاء وأشياء من هذا القبيل لا
اضطراب الرمز. لذلك ، أنا دائمًا ما أكون مثالًا على ذلك
الطريقة ، حيث أميل إلى كتابة اختبار واحد في كل سطر ، وبعد ذلك سأقوم بمحاذاة هذه الطريقة.
لذلك ها هو الاختبار الثاني. الشيء الوحيد الذي هو مربكة بعض الشيء هو أن نلاحظ ذلك
هناك نوعان من الأقواس المطلوبة هنا. هذا ، هذا أول واحد فقط أرصدة
الأقواس للنهايات. ثم الثاني ، هو الذي يغطي
اختبار كامل ، لذلك يتطابق مع ذلك ، أول واحد. لذلك إذا تركت ذلك ،
في الواقع أستطيع أن أوضح ذلك ، لذلك من السهل جدًا ترك هذا الخطأ ،
"عليك أن تدرك كيندا بخير أحتاج اثنين هناك. لذلك في هذه الحالة ، لا
دائمًا ، ولكن زر التشغيل لـ ، فقط لهذه الفئة ، سيحاول أن يوفر لك
رسالة خطأ ، مثل أوه ، يبدو أن هناك أقواس مفقودة هناك. وبالتالي
الآن قم بتكوينها بهذه الطريقة سنحصل عليها ، نحن لا نزال في حالة جيدة. كما قلت قبل كل من
هذه الاختبارات كاملة والوقوف من تلقاء نفسها. لذا ، فقط بالطريقة ذاتها التي قمنا بها
الأشياء من قبل. هناك شكل واحد من التعليمات البرمجية يبدو صحيحًا ولكنه خاطئ.
ولذا سأقوم بإنشاء هذا هنا. لذلك إذا كنت تكتب فقط بهذه الطريقة. لذلك أنا سوف
مجرد نوع من نطقها. row.getField ("الاسم") ، الذي يبدأ بـ ("a") AND
endsWith ( "ص"). لذلك فقط إلى الأذن للإنسان ، كانوا يعرفون
ماذا يعني ذلك ، لكن هذا الرمز لا يعمل. المشكلة هي المصطلح الثاني. على
من تلقاء نفسها ، لا معنى له. حق؟ لا تقف فقط من تلقاء نفسها مثل الغايات
مع ، حسنا لا معنى له. عادة ما نحتاجه هو ، سنضع في
المؤشر هنا ، سنحتاج إلى row.getField ("الاسم") أو "الرتبة" أو أيًا كان
يكون. لذلك هذا لا يعمل. كل ، كل ، إلى اليسار واليمين
علامة الضم ، كل مهمة يجب أن تكون كاملة. حتى في هذه الحالة ، أنا فقط فرز
of hit تراجع في فايرفوكس هنا ، إذا كنا نريد أن نتحدث عن الاسم ، مثلنا
تهجئته للاختبار الأول ، وبعد ذلك نقوم بتوضيحه بالكامل
الاختبار الثاني. لذلك كل اختبار منطقي للكمبيوتر. حسنًا ، سأفعل
حاول مثال آخر هنا. لنرى. حتى الآن ، إذا قمت بتشغيل هذا ، فإنه يظهر فقط
جميع أسماء "أ" ، وهو كثير جدا. ما يقوله بيان المشكلة هو ، التغيير
الرمز بحيث يطبع الأسماء التي تبدأ بـ "A" والرتبة أقل من 50. لذا ،
أوه ، إليك الاختبار الأول ، وسأضيف اثنين من علامات الضم ، وأعود لنقم بذلك
قل الصف ، الذي يبدأ ، والذي يبدأ ("A") هو اختبار واحد ، والآن سنضيف ، أنا
ستعمل على دمجها مع AND ، مع الاختبار الثاني ، حيث أقول الترتيب ، فلنقم بذلك
قل أقل من أو يساوي 50. لذلك أعتقد أنني سأحاول ذلك ، نعم حتى ينجح. وبالتالي
ما زلنا نحصل على أسماء "أ" لكن الآن نصل إلى المرتبة 50. سأحاول فقط
مثال ثالث هنا. حسنًا ، الآن سنفعل مثالًا مع OR. تغيير الكود
أدناه ، لذلك يطبع الصفوف حيث يكون التالي صحيحًا. يبدأ الاسم بـ "X" أو
نجوم النجوم مع "Y" ، أو اسم النجوم مع "C". لذلك إذا ركضت للتو ، قم بتشغيلها بشكل صحيح
الآن ، رمز هناك فقط يفعل "X". وبالتالي
أريد استخدام OR. ونحن سوف نسخ هذا. لذلك باستخدام اختبار OR. تصنع
طرق متعددة ليصبح الاختبار الشامل صحيحًا. انها مثل ، حسنا ، إذا كان الاختبار
صحيح إذا كان هذا صحيحًا ، أو إذا كان هذا الشيء الآخر صحيحًا. لذلك هو نوع من الاتساع.
it gets a little, a little long. So what's happened in this case is I, actually I hit
return after the ampersand. I went down here and I hit the space bar, to get the
row over here and kind of line it up. So I wrote the second test on a second line.
That's optional but you can do it. Putting in spaces and stuff like that doesn't
upset the code. So, I'm, always my examples I'll sort of neaten up in this
way, Where I'll tend to write one test per line, and then I'll align them this way.
So here's the second test. The only thing that's a little confusing is to note that
there are two parentheses are required here. This, this first one just balances
the parentheses for the endsWith. And then the second one, is the one that covers the
entire test, so it matches up to the, that first one. So if you leave that out,
actually I can illustrate this, so it's a pretty easy error to leave that one out,
'cuz you have to kinda realize alright I need two there. So in that case, not
always, but the run button for the, just for this class, will try to give you an
error message, like oh, it looks like there's a missing parentheses there. So
now form it that way we'll get them, we're still good. As I said before each of
these tests is complete and stand on its own. So just syntactly just the way we did
things before. There's this one form of the code that looks right but is wrong.
And so I'll create that here. So if you just write it this way. So I'll
just sort of pronounce it. row.getField("name"), that startsWith("a") AND
endsWith("y"). So just to the ear to a human, they would know
what that means, but this code does not work. The problem is the second term. On
its own, doesn't make sense. Right? Doesn't just stand on its own like ends
with, well it doesn't make sense. Usually what we need is, we're gonna put in a
cursor here, we would need row.getField("name") or "rank" or whatever it's gonna
be .endsWith. So this is not working. Each, each, to the left and the right of
the ampersand, each task has to be complete. So in this case, I'll just sort
of hit undo in Firefox here, the, if we wanna be talking about name, like we
spell it out for the first test, and then we also just completely spell it out for
the second test. So each test makes sense to the computer. Alrighty, So, I'm gonna
try another example here. Let's see. So right now, if I run this, it just shows
all the "A" names, which is quite a lot. What the problem statement says is, change
the code so it prints the names that start with "A" and the rank is less than 50. So,
oh here's, here's the first test, and I'll add two ampersands, and return let's
say row, that starts, that startsWith("A") is one test and now we're gonna add, I'm
gonna combine it with an AND, with the second test, where I'll say rank, oh let's
say less than or equal to 50. So I think I'll try it, yeah so that works. So
we still get "A" names but now we're just getting up to rank 50. I'm just gonna try
a third example here. Alright, now we'll do an example with OR. Change the code
below, so it prints rows where the following is true. Name starts with "X", or
the name stars with "Y", or the name stars with "C". So if I just run, run it right
now, the code that's there just does "X". So
I wanna use OR. And we'll copy this. So by using an OR-test. You make
multiple ways for the overall if-test to be true. It's like, well, the if-test were
true if this one is true, or if this other thing is true. So it's kind of a widening.
حتى هنا أقول ، أو row.getField - "Y". لذلك ، على المدى السابق ، حصلنا فقط على "X".
حسنا؟ لذلك سوف أدير هذا. أوه ، حتى الآن نحصل على "X" و "Y". لذلك هناك "يوسف" و
"Yeritza". لاحظ أنني ، في نهاية المطاف ، كان هدفي هو إظهار "X" أو "Y" أو "Z" ،
لكنني أعتقد أنه من الجيد أن تحصل على الكود
إلى نوع من نصف الحالة المبنية ، ولكن من المنطقي. أنت تعرف ، فقط حاول الجري
إنه ونوع من التحقق ، يا ينجح قبل أن يفعل كل شيء.
هذا نوع من قواعد كود الكمبيوتر الكلاسيكية. لا تحاول والقيام كله
شيء في خطوة واحدة ، أو يبدأ بـ ("Z"). لذا أنا
اعتقد جزئيا ما أراه هنا هو. يمكن أن يكون لديك العديد من عمليات التشغيل و ANDS متعددة
سلسلة الأشياء معا. لذلك دعونا نجرب ذلك ، هناك ، هناك عدد لا بأس به من "Z"
أسماء. إذن لدينا هنا "X" أو "Y" أو "Z" ،
لذلك هذا يدل على اثنين من القضبان العمودية ، ثم في هذه الحالة لقد مدمن مخدرات معا
ثلاثة أشياء. بالنسبة لهذه الفئة ، سأستخدم فقط مجموعة من الأشياء
متصل بـ AND أو مجموعة من الأشياء المرتبطة بـ OR. أنا لن الجمع بينهما.
ادمجهم فقط مع بعض الحالات الأخرى المثيرة للاهتمام ولكن أنا
لا ، أنا لا أريد حقا الدخول. أنها لا تساعد كثيرا حقا. شيء آخر أنا
يجب أن أذكر هذا ، حسناً ، لذا يجب أن أعتذر عن ذلك. هذه
يمثل نشاط علامة الضم نوعًا من الحوادث التاريخية أو الأعمال العارضة العمودية.
اختارت اللغة ، اللغة المؤثرة هذا ، مثل منتصف السبعينيات. ومرة واحدة
اختارت اللغة هذا الرمز لتعني OR ، فكرت بعض اللغات الأخرى ، حسناً
يجب علينا فقط استخدام تلك الاتفاقية. وهكذا كان مجرد كرة الثلج ، أين الآن ،
هذا هو اتفاقية شائعة جدا. لذلك شعرت ، حسناً ، إنه نوع من الغموض ، لكن.
هذه هي الاتفاقية ، لذا يجب علينا المضي قدمًا وتعلم ذلك. حسنا ، لذلك ،
دعنا ننتقل قليلا هنا. في الواقع ، ما قمت بإعداده هو مجرد
عدد كبير من الأمثلة هنا. وهناك زر حل العرض هنا ، لذلك إذا كنت
تريد ممارسة أو مراجعة هذه الأمثلة التي قمت بها ، يمكنك العودة وهي
جميع فرزها هنا. ما سأحاول فقط ، الستة الأولى. لذلك ، أنا اكتب في
رمز لهؤلاء وسأترك للآخرين كنوع من الممارسة الإضافية ل
الناس الذين يريدون ذلك. حسنًا ، هكذا يقول الأول ، يبدأ الاسم بـ "Ab" ، أو يبدأ بـ
"ميلان". لذلك أقول أن هناك بعض الرموز هنا التي نبدأ بها بالفعل. لذلك يبدأ
مع "أب". وماذا كان؟ أو يبدأ بـ "Ac". لذلك هذا واحد يبدأ هنا ، لذلك هذا
يجب أن يكون OR أو اثنين مختلفين أو. لنجرب ذلك. لذلك لدينا "A" ، "AC" أين
اسم "التيار المتردد"؟ يا. انظروا لقد ارتكبت خطأ. كتبت "أب" مرتين. حسنا. هناك نذهب.
حسنا ، هناك "AC". أظهر ذلك مثالًا مثيرًا للاهتمام على الخلل ، حيث توجد أخطاء في بعض الأحيان
أخطاء بناء الجملة حيث تضغط على زر التشغيل ، إنه فقط ، كما تعلمون ، إنه يتعطل
وتحصل على بعض الناتج الأحمر. ولكن في بعض الأحيان علة هو ذلك تماما. كتبت
شيء يعني شيئًا للكمبيوتر ، لكنه ليس ما قصدته.
وبالتالي فإن الإخراج ليس ما كنت أتوقعه ، فأنا مرتبك قليلاً.
هذا هو المستوى الأعلى من الأخطاء في هذه الدورة. انها الى حد ما
مشترك مع أجهزة الكمبيوتر. حسنًا ، دعنا نرى ، المرحلة التالية. الاسم يبدأ بـ "Ab" ، أو
"AC" أو "Al". حسنا أرى ذلك. لذلك يمتد هذا فقط. هذا يظهر فقط أنه يمكنك الحصول عليها
ثلاثة. لذلك سأقول شريط عمودي. سوف لصق هذا فيه. لذلك كان "AC" ،
لذلك "Ab" و "Ac" لا يعطينا الكثير ولكن مع "Al" أنت تعلم أنه كثير جدًا.
حسنا. لذا فإن الاسم التالي هو ، الاسم يبدأ بـ O وينتهي بـ A. لذا أقول
يبدأ ، سأترجمها فقط. يبدأ بـ "O" وينتهي بـ "a". حسنا. دعونا
جرب ذلك. أوه ، هناك واحد فقط ، "أوليفيا". ماذا
نوبة ، تبدأ بـ O والجنس فتاة؟ لذلك ، سوف نحصل على الجنس فقط هنا ، و
ثم نقوم باختبار هذا ليس باستخدام startWith ينتهي ، ولكن فقط مع ==.
لذلك يا فتاة. أوه ، هناك اثنان فقط. حتى نحصل على الزيتون. حسنا،
ينتهي الاسم بـ "a" والجنس هو ماذا؟ غير هذا إلى name.endsWith ("a") و
حسب مثالي السابق ، ادعائي السابق ، سأقوم فقط بقص ذلك.
الآن أصبح نصف التصميم صحيحًا ، ينتهي الاسم بـ "a". ولكن يمكنني تشغيل ذلك والتحقق من نوع ما ،
جميع rigt هذا يعمل. وبعد ذلك ، خذ شيء عملك ، وتمديده. ماذا
هل اردت في هذه الحالة أردت يا ، الأسماء تنتهي بـ "a" والجنس فارغ.
حسنا. يسوع ، لايل. أسماء الفتاة لا. صبي. أوه ، حسناً ، هناك القليل ، جوشوا ،
عزرا. حسنًا ، سأقوم بهذا الأخير ، الرقم ستة هو أقل من عشرة ، والجنس هو
فتاة. لذلك سوف أقوم بتغيير هذا إلى "رتبة". بدلا من ينتهي مع. سأقول ، أقل من أو يساوي
الى عشرة. و ، لذلك ، أنا الآن لا تستخدم startWith ، أو
ينتهي مع أي من هذه ولكن فقط لاحظ كل واحد من هؤلاء هو كامل و
الاختبار الصحيح كما ناقشنا من قبل. هذا واحد ، وهذا واحد وأنا فقط
الانضمام إليهم من هناك. لذا المرتبة أقل من عشرة ، والجنس في هذه الحالة هو فتاة.
لنجرب ذلك. لذلك هذا منطقي. نحن فقط نحصل على واحد ، اثنان ، ثلاثة ، أربعة منهم.
So here I'll say, OR row.getField - "Y". So, for the previous run, we only got "X".
Alright? So I'm gonna run this. Oh, so now we get "X" and "Y". So there's "Yusuf" and
"Yeritza". Notice that I, my goal ultimately was to show "X" or "Y" or "Z",
but I think it is kinda nice if you get the code
into a kind of half built state, but where it makes sense. You know, just try running
it and kind of verify, oh that works before going on to do the whole thing.
That's kind of a classic computer code rule of thumb; don't try and do the entire
thing in one step, OR startsWith("Z"). So, I
guess partly what I'm showing here is. You can have multiple ORs and multiple ANDs and
string things together. So let's try that, There it goes, Quite a few "Z"
names. So there we have it, "X" or "Y" or" "Z,
so this shows the two vertical bars, and then in this case I have strung together
three things. For this class, I will only, I'll use either a bunch of things
connected with AND or a bunch of things connected with OR. I won't combine them.
Combine them just brings up some other cases that are kind of interesting but I
not, I don't really want to get into. They don't really help a lot. Other thing I
should mention about this, alright so I should just apologize to this. This
ampersand business is sort of a historical accident, or the vertical bar business.
Language, influencial language chose this in, like the mid'70s. And once one
language had chosen this symbol to mean OR, some other languages thought, oh, well
we should just use that convention. And so it just kinda snowballed, where now,
that's a very common convention. So I felt like, well, it's kind of obscure, but.
That's the convention so we should just go ahead and learn that one. Alright, So,
let's scroll down here a little bit. So actually, what I have set up is just a
large number of examples here. And there's a show solution button here, so if you
want practice or to review these examples I've done, you could come back and it's
all sorted here. What I'll is I'll just try the, the first six. So, I'll type in
the code for those and I'll leave the others as kind of extra practice for
people who want it. Okay, so the first one says, name starts with "Ab", or starts with
"Ac". So I'll say there's some code here that we start with already. So it starts
with "Ab". And what was it? OR starts with "Ac". So this one starts with here, So this
should be an OR, Two different or's. Let's try that one. So we got "A", "Ac" Where's
the "Ac" name? Oh. Look I made a bug. I typed "Ab" twice. Okay. There we go.
Ok, there's an "Ac". That showed that interesting example of a bug, where sometimes bugs are
syntax errors where you hit the run button and it, it just, you know, it, it crashes
and you get some red output. But sometimes a bug is just that. I typed
something that does mean something to the computer, but it's not what I intended.
And so then the output is not what I expected, then I'm a little bit confused.
So that's the more higher level kind of bug in this course. It's fairly
common with computers. Okay, let's see, next one. Name starts with "Ab", or
"Ac", or "Al". Oh, I see. So this just extends. This just shows that you can have
three. So I'll say vertical bar. I'll paste this in. So it was "Ac",
so "Ab" and "Ac" doesn't give us a lot but with "Al" you know it's quite a lot.
Okay. So the next one was, name starts with O and ends with A. So I'll say
starts, I'll just translate it. Starts with "O" AND ends with "a". Alright. Let's
try that. Oh, there's only one, "Olivia". How
bout, starts with O and gender is girl? So, we'll just get gender right here, and
then we test that is not with startsWith endsWith, but just with ==.
So, O AND girl. Oh, there's only two. So we get Olive. Okay,
name ends with "a" and gender is what? Change this to name.endsWith("a"), and
per my previous example, my previous claim, I'll just cut that out.
Now it's half built right, name ends with "a". But I could run that and sorta verify,
all rigt that's working. And then, take your working thing, and extend it. What
did I want? In this case I wanted oh, names ends with "a" and gender is blank.
Okay. Jesus, Lyle. Girl names neither. Boy. Oh, well, there's a few, Joshua,
Ezra. Okay, I'll do this last one, number six Rank is less than ten, and gender is
girl. So I'll change this to "rank". Instead of endsWith. I'll say, less than or equal
to ten. And, so, Now I'm not using startsWith, or
endsWith for either of these but just notice each one of those is a complete and
correct test as we discussed before. That one is, and that one is and I'm just
joining them from there. So rank is less than ten, and gender in this case is girl.
Let's try that. So that makes sense. We just get one, two, three, four of them.
واحد من خلال عشرة أسماء فتاة. هذا النوع من الاهتمام في هذا ، هذا أنا
أعتقد لديه ترجمة الإنجليزية معقولة. ما هذا ، هو. ما يقوله هذا هو الأعلى
عشرة أسماء فتاة ، وبعد ذلك ، يمكننا أن نعبر عن هذا الشيء والشيء. حيث رتبة أقل
من أو يساوي عشرة والجنس فتاة. أو بالفعل
في النهاية يمكننا أن نعبرها كرمز. لذلك فقط انزلها إلى ، إلى حيث الكمبيوتر
يمكن أن تفعل ذلك في الواقع. لذلك هناك بعض المشاكل هنا والحلول كلها
متاح. لذلك هذه فرصة جيدة للمجيء ومراجعة ما قمت به أو تجربته
قليلا من الممارسة قبل أن نفعل التمارين. كوز هذه ، إلى حد ما ، هي -
أصبحت لغات الكمبيوتر الآن كبيرة بما يكفي بحيث يمكنني حقًا الحصول على الكثير منها
من مختلف] غير مسموع [بخير.
One through ten girl names. This one's kind of interesting in that this, this I
think has a sensible English translation. What this is, is. What this says is top
ten girl names, And then, We can phrase that as this AND thing. Where rank is less
than or equal to ten and gender is girl. Or indeed
ultimately we can phrase it as code. So just get it down to, to where the computer
can actually do it. So there's a few more problems here and the solutions all
available. So this is a good opportunity to come and review what I did or try a
little bit of practice before we do the exercises. Cuz these, in some sense, are -
computer languages have now gotten big enough that I can really we can have a lot
of different [inaudible] alright.
الجدول المنطقية المنطق
في هذا القسم ، سنقوم بتوسيع الشفرة الخاصة بنا مع "المنطق المنطقي" .. باستخدام و / أو الجمع بين اختبارات صواب / خطأ متعددة.
منطق منطقية: && || !
تريد أن تكون قادرة على الجمع بين الاختبارات ، باللغة الإنجليزية مثل هذا
- يبدأ الاسم بـ "A" وينتهي بـ "y"
في الكود "المنطق المنطقي"
و
&&
(اثنين من علامات العطف)
أو
||
(قضيبان عموديان)
ليس
!
(علامة تعجب ، نحن لا نفعل هذا واحد)
آسف بناء الجملة هو حادث بناء الجملة التاريخي خفي
المنطق المنطقي مثال 1
table = new SimpleTable ("baby-2010.csv") ؛
لـ (الصف: الجدول) {
if (row.getField ("name"). يبدأ بـ ("A") &&
row.getField ("name"). endWith ("y")) {
طباعة (الصف).
}
}
ينضم && إلى اختبار يبدأ مع اختبار ينتهي
تتم كتابة الاختبار بالكامل عبر سطرين لأنه طويل نوعًا (اختياري)
حكم مستقل
- لاحظ أن الاختبارات التي انضم إليها && || هي اختبارات كاملة بناءً على تلقاء نفسها ، ثم انضم إلى && أو ||
تبدو معقولة ولكنها غير صحيحة:
row.getField ("name" .startsWith ("A") && endWith ("y")
خطأ شائع: عدد قليل جدًا من الأقواس الصحيحة حول الاختبار
يحاول Run الكشف عن بعض الأخطاء الشائعة ، مثل حذف {، أو الكتابة & بدلاً من && ، إعطاء رسالة خطأ
المنطق المنطقي مثال 2
قم بتغيير الكود أدناه بحيث يطبع الصفوف حيث يكون ما يلي صحيحًا:
يبدأ الاسم بـ "A" والرتبة هي <= 50
table = new SimpleTable ("baby-2010.csv") ؛
لـ (الصف: الجدول) {
if (row.getField ("name"). يبدأ مع ("A")) {
طباعة (الصف).
}
}
عرض الحل
المنطق المنطقي مثال 3
الآن افعل مثال مع أو | - قم بتغيير الكود أدناه لطباعة الصفوف حيث يكون ما يلي صحيحًا:
يبدأ الاسم بـ "X" أو يبدأ الاسم بـ "Y" أو يبدأ الاسم بـ "Z"
table = new SimpleTable ("baby-2010.csv") ؛
لـ (الصف: الجدول) {
// رمزك هنا
if (row.getField ("name"). يبدأ مع ("X")) {
طباعة (الصف).
}
}
عرض الحل
العديد من الأمثلة المنطقية
فيما يلي رمز العمل لاختبار أسماء Popular A المذكور أعلاه.
table = new SimpleTable ("baby-2010.csv") ؛
لـ (الصف: الجدول) {
if (row.getField ("name"). يبدأ بـ ("A") &&
row.getField ("المرتبة") <= 50) {
طباعة (الصف).
}
}
تجارب لمحاولة:
بالنسبة لهذه الأمثلة ، سنستخدم واحداً من && || لكن ليس كلاهما.
1. يبدأ الاسم بـ "Ab" أو يبدأ الاسم بـ "Ac"
2. يبدأ الاسم بـ "Ab" أو يبدأ الاسم بـ "Ac" أو يبدأ الاسم بـ "Al"
3. يبدأ الاسم بـ "O" وينتهي الاسم بـ "a"
4. الاسم يبدأ بـ "O" والجنس هو "فتاة"
5. الاسم ينتهي بـ "a" والجنس هو "boy"
6. الترتيب هو <= 10 والجنس هو "فتاة" (الترجمة: "أفضل 10 أسماء بنات")
7. الترتيب هو <= 10 أو الجنس "فتاة" (هذا التصنيف لا معنى له ، لكن ما الذي تطبعه؟)
8. ينتهي الاسم بـ "ia" والجنس هو "فتى" (ههه ، ثم جرب النوع هو "فتاة")
9. ينتهي الاسم بـ "io" والجنس هو "فتاة" (ثم حاول "boy")
10. ينتهي الاسم بـ "o" والجنس هو الولد والمرتبة هي> = 900
رمز حل التجربة:
Table Boolean Logic
In this section, we'll extend our code with "boolean logic" .. using and or to combine multiple true/false tests.
Boolean Logic: && || !
Want to be able to combine tests, in English like this
-- Name starts with "A" and ends with "y"
In code "boolean logic"
and
&&
(two ampersands)
or
||
(two vertical bars)
not
!
(exclamation mark, we're not doing this one)
Sorry syntax is a bit cryptic -- historical syntax accident
Boolean Logic Example 1
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").startsWith("A") &&
row.getField("name").endsWith("y")) {
print(row);
}
}
The && joins a startsWith test and a endsWith test
The whole test is written across two lines because it is kind of long (optional)
Standalone rule
--Note that the tests joined by && || are syntactically complete tests on their own, then joined with && or ||
Looks reasonable but is incorrect:
row.getField("name).startsWith("A") && endsWith("y")
Common error: too few right parenthesis around the test
Run tries to detect certain common errors, like omitting the {, or typing & instead of &&, giving an error message
Boolean Logic Example 2
Change the code below so it prints rows where the following is true:
Name starts with "A" and rank is <= 50
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").startsWith("A")) {
print(row);
}
}
Show Solution
Boolean Logic Example 3
Now do an example with or || -- change the code below to print rows where the following is true:
Name starts with "X" or name starts with "Y" or name starts with "Z"
table = new SimpleTable("baby-2010.csv");
for (row: table) {
// your code here
if (row.getField("name").startsWith("X")) {
print(row);
}
}
Show Solution
Many Boolean Examples
Here is the working code for the Popular A names test mentioned above.
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").startsWith("A") &&
row.getField("rank") <= 50) {
print(row);
}
}
Experiments to try:
For these examples, we'll use one of && || but not both.
1. name starts with "Ab" or name starts with "Ac"
2. name starts with "Ab" or name starts with "Ac" or name starts with "Al"
3. name starts with "O" and name ends with "a"
4. name starts with "O" and gender is "girl"
5. name ends with "a" and gender is "boy"
6. rank is <= 10 and gender is "girl" (translation: "top 10 girl names")
7. rank is <= 10 or gender is "girl" (this one doesn't make a ton of sense, but what does this print?)
8. name ends with "ia" and gender is "boy" (hah, then try with gender is "girl")
9. name ends with "io" and gender is "girl" (then try "boy")
10. name ends with "o" and gender is boy and rank is >= 900
Experiment solution code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q2
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").startsWith("B") &&
row.getField("name").endsWith("a")) {
print(row);
}
}
Q3
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").endsWith("i") &&
row.getField("gender") == "boy") {
print(row);
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Table startsWith endsWith
يبدأ الجدول مع انتهاء
Dies ist ein sehr kurzer Abschnitt. Ich möchte nur hinzufügen
Ein zusätzlicher Test, der sehr gut mit den Babynamendaten funktioniert. Das ist es also
eine Alternative zu dem, was wir vorher benutzt haben
die Babynamendaten. Und ich möchte Ihnen diese Funktionen zeigen, die aufgerufen werden
beginnt mit und endet mit. Und diese arbeiten an Saiten. Und um es zu erklären, werde ich nur
Schauen Sie sich den Code in meinem Beispiel hier an. So funktioniert das. Ist, das ist alles das gleiche wie wir zuvor gesehen haben. Ich habe den Tisch geöffnet,
Ich habe die Schleife, sie haben die if-Anweisung, wo ich bin
jede Reihe betrachten. Also schauen wir uns die Aufgabe hier an. Also der erste
Ein Teil der Aufgabe ist derselbe wie zuvor. Also sage ich row.getField ("name") so
Ich ziehe den Namen aus der Reihe, und das ist eine Zeichenfolge. Und vorher haben wir getan
Beispiele wie, oh, ist es gleich "Abby" oder "Robert" oder was auch immer, mit dem == - Test.
Die Art und Weise, wie diese Funktionen beginnen und enden, ist die Syntax
lustig auf eine gewisse Art. Es hat einen Punkt ... und Sie markieren ihn einfach rechts
Seite des Namens, so bekomme ich den Namen und ich sage sofort .startsWith. Und
dann, innerhalb der Klammer für die Starts, können Sie einfach alles sagen.
Also sage ich hier "Ab". Und was dieser Test ist, beginnt der Name mit den Buchstaben "Ab"?
Und wenn es wahr ist, ist der Anfang mit wahr, und wenn es nicht wahr ist, ist es falsch. So dass es,
es liest irgendwie. Weißt du, beginnt der Name mit "Ab"? Also lass uns einfach
Versuch es. Also, wenn ich das hier nur durchführe, werden Sie sehen, dass es durch die 2.000 Zeilen gegangen ist,
und es ist nur herausgegriffen, wir werden sehen, dass sie alle mit "Ab" beginnen. Es ist nur; es war
wahr, für alle diese. Also, was auch immer ich hier tippe. Wir werden Reihen bekommen, in denen der Name steht
fängt damit an, also kann ich tippen ... ich weiß nicht, wir werden es umkehren. ich kann tippen
in "Ba" gibt es nicht so viele. Oder ich kann vielleicht nur "A" in Großbuchstaben eingeben, nicht zwei Buchstaben.
هذا هو ، سيكون مقطع قصير جدا. أريد فقط أن أضيف على
اختبار إضافي يحدث بشكل جيد للغاية مع بيانات اسم الطفل. اذن هذا هو
ستكون بديلاً عن == الذي كنا نستخدمه من قبل
اسم الطفل البيانات. وأريد أن أريك هذه الوظائف التي تسمى
يبدأ مع وينتهي. وهذه تعمل على الاوتار. ولشرح ذلك ، أنا فقط
انظر إلى الكود في مثالي هنا. الطريقة التي يعمل بها هذا. هو ، كل هذا هو نفسه كما رأينا من قبل. لقد فتحت الطاولة ،
لدي الحلقة ، لديهم if-statement ، حيث أنا
النظر في كل صف. لذا فقد ألقينا نظرة على المهمة التي تركت هنا. لذا الأول
جزء من المهمة هو نفسه الذي قمنا به من قبل. لذلك ، أقول row.getField ("الاسم") هكذا
أنا أسحب الاسم من الصف ، وهذه سلسلة. وقبل ذلك قمنا به
أمثلة مثل ، أوه ، هل تساوي "Abby" أو "Robert" أو أي شيء ، مع == - الاختبار.
الطريقة التي يبدأ بها هذا مع نهاياته - هي وظائفه ، هي بناء الجملة
نوع من مضحك. يحتوي على نقطة ... وعليك فقط وضع علامة في اليد اليمنى
جانب من الاسم لذلك أخرج الاسم وأقول على الفور .startsWith. و
بعد ذلك ، داخل قوس البداية ، يمكنك قول أي شيء.
لذلك أنا هنا أقول "أب". وما هي الاختبارات ، هل يبدأ الاسم بالأحرف "Ab"؟
وإذا كان هذا صحيحًا ، فستكون البداية صحيحة ، وإذا لم تكن صحيحة. لذلك ،
يقرأ كيندا. أنت تعرف ، هل ، هل ، هل يبدأ الاسم بـ "Ab"؟ لذلك ، دعونا فقط
جربها. لذلك إذا قمت بتشغيل هذا ، فما ستراه هو أنه مر عبر 2000 صف ،
وقد تم اختياره للتو ، سنرى أنهم يبدأون جميعًا بـ "Ab". انه فقط؛ كان
صحيح ، لكل هؤلاء. لذلك كل ما اكتب هنا. سنحصل على صفوف حيث الاسم
يبدأ بذلك ، لذا ، يمكنني الكتابة ... لا أعرف ، سنقوم بعكس ذلك. أستطيع أن أطبع
في "با" ، أوه ، ليس هناك الكثير. أو يمكنني كتابة ربما الأحرف الكبيرة "A" ، وليس حرفين.
This is a, going to be a very short section. I just want to add on
an additional test that happens to work very well with the baby name data. So this is
going to be an alternative to the == that we were using before on
the baby name data. And I want to show you these functions, which are called
startsWith and endsWith. And these work on strings. And to explain it, I'll just
look at the code in my example here. The way this works. Is, all this is the same as we've seen before. I've opened the table,
I have the loop, they have the if-statement, where I'm
looking at each row. So we've just look at the task left right here. So, the first
part of the task is the same as we've done before. So, I say row.getField("name") so
I'm pulling the name out of the row, and that's a string. And previously we've done
examples like, oh, is it equal to "Abby" or "Robert" or whatever, with the ==-test.
The way these startsWith and endsWith -functions work, is the syntax is
kind of funny. It has a dot... And you just tag it right on to the right hand
side of the name so I get out the name and I immediately say .startsWith. And
then, inside of the parenthesis for the startsWith, you could just say anything.
So here I say "Ab". And what that tests is, does the name begin with the letters "Ab"?
And if it does it's true, the startsWith is true, and if it doesn't it's false. So it,
it kinda reads. You know, does, does, does the name start with "Ab"? So, let's just
try it. So if I just run this, what you'll see is it's gone through the 2,000 rows,
and it's just picked out, we're gonna see they all start with "Ab". It's just; it was
true, for all of those. So whatever I type here. We're gonna get rows where the name
begins with that, So, I can type... I don't know, we'll reverse it. I can type
in "Ba", oh, there's not that many. Or I can type maybe just uppercase "A", not two letters.
Wir werden ziemlich viele, ziemlich viele Namen bekommen, beginnend mit "A". Wenn ich
tippe hier ein kleines "a", und ich laufe. Wir bekommen eigentlich keine Ausgabe. Und was ist los
Auf dem Computer steht der Großbuchstabe "A" und der Kleinbuchstabe "a", das sind
nur zwei verschiedene Buchstaben. Und so beginnen in diesen Daten die Namen alle mit einem oberen
Groß- / Kleinschreibung und alle anderen Buchstaben sind Kleinbuchstaben. Also beginnend mit ("a")
- das ist eine feine Sache, aber das hat keine Ergebnisse, wohingegen, wenn ich ein Obermaterial lege
Geben Sie hier "A" ein und führen Sie es aus, dann erhalten wir sie alle.
Richtig, und Sie können sogar sehen, wie ja, sie beginnen dann später mit einem Großbuchstaben
Buchstaben sind Kleinbuchstaben. Sie müssen das also nur beim Test wissen. Was war ich noch?
hier machen? Versuchen wir mal "Z". Wenn ich also nach Starts mit ("Z") suche, bekommen wir alle
die Namen; da sind ein paar. Oder ich könnte es eingrenzen. Ich könnte sagen, na ja, vielleicht
es muss mit "Za" beginnen. Dann bekommen wir weniger. Und vielleicht könnte ich "Zai" sagen.
Dann kommen wir auf vier, und dann könnte ich es so sagen, ich werde es so sagen
"Zai" ... ich weiß nicht, "x". Dann mache ich es, oh
dann bekomme ich nichts. Es ist also durchaus möglich, einen Test dort zu schreiben, wo es nur geht
falsch. Für alle 2000 Zeilen und dann druckt es einfach nichts. Also werde ich es einfach auf "Zai" zurück,
und dann machen wir einfach die. Damit die Starts mit funktionieren, und für diese
Erste Beispiele: Wir werden es immer so verwenden. Also gehen wir die Reihe
für die baby daten bekommen wir den namen raus und dann sagen wir sofort .startsWith, to
Überprüfen Sie die linke Seite des Namens. Also, wie Sie sich vorstellen können, gibt es auch eine
.endsWith das die andere prüft, die rechte Seite des Namens. Also, wenn ich sage,
endsWith ("z"), ich führe das aus, oh gees, überraschend wenige von denen, so dass Picks
Anscheinend gibt es in diesem gesamten Datensatz nur drei Namen, die mit "z" enden. So
Ich könnte sagen, oder ich könnte mehrere nehmen
Briefe. Ich könnte sagen, endet mit ("ly"). Also noch ein paar oder ich, ich versuche es mit ("la"). Und
Ich werde das laufen lassen. Oh, dann gibt es einige davon. Sie können sehen, ich denke diese
sind auch alle Mädchennamen. Ich meine, das ist nur kulturell das Muster in
Englisch, das, Mädchenname oder "la" ist, soll der Name eines Mädchens sein. Also diese
sind, das sind nur zwei zusatz-, nur zwei zusatzfunktionen. Und wir werden, wie ich war
Sagen wir, wir werden sie nicht für die Namen im Baby-Datensatz, Baby-Datensatz, verwenden.
Aber sie werden uns erlauben, noch interessantere Probleme zu lösen.
سنحصل على الكثير والكثير من الأسماء ، بدءًا من "A". اذا انا
اكتب الحالة الصغيرة "a" هنا ، وأركض. نحن في الواقع لا تحصل على الإخراج. وماذا يحدث
هناك في الكمبيوتر الحالة العليا "A" والصغيرة "a" ، تلك
فقط رسالتين مختلفتين. وهكذا في هذه البيانات ، تبدأ جميع الأسماء بالأعلى
رسالة الحالة ثم جميع الحروف الأخرى هي صغيرة. إذن البدء بـ ("a")
- هذه دقة ، ولكن هذا له نتائج صفرية ، في حين أنني إذا وضعت عالياً
حالة "A" هنا وتشغيلها ثم نحصل عليها جميعا.
إلى اليمين ، ويمكنك حتى أن ترى كيف نعم ، فإنها تبدأ بحرف كبير في وقت لاحق
الحروف صغيرة. لذلك تحتاج فقط إلى معرفة ذلك في الاختبار. ماذا كنت كذلك
سوف تفعل هنا؟ لنجرب "Z". لذلك إذا بحثت عن startWith ("Z") ، فسنحصل على كل شيء
الأسماء؛ هناك القليل هناك. أو يمكنني تضييقه. أستطيع أن أقول ، حسناً ، ربما
يجب أن تبدأ بـ "Za". ثم نحصل على عدد أقل. وربما أستطيع أن أقول "زاي".
ثم ننخفض إلى أربعة فقط ، وبعد ذلك يمكنني أن أقول ذلك ، سأقول ذلك
"زاي" ... أنا لا أعرف ، "س". ثم أديرها ، أوه
ثم أحصل على شيء. إذاً ، من الممكن بالتأكيد كتابة اختبار حيث يكون مجرد
خاطئة. لجميع الصفوف 2000 وبعد ذلك فقط يطبع شيئا. لذلك أنا فقط إعادته إلى "زي" ،
ثم نحن فقط نفعل ذلك. بحيث تبدأ وظيفة مع ، ولهذه
الأمثلة الأولى ، سنستخدمها دائمًا بهذه الطريقة. لذلك نحن نذهب الصف
بالنسبة لبيانات الطفل ، نخرج الاسم ، ثم نقول على الفور .startsWith ، إلى
تحقق من الجانب الأيسر من الاسم. لذلك ، كما قد تتخيل ، هناك أيضًا
.فيما يختبر الآخر ، الجانب الأيمن من الاسم. لذلك إذا قلت ،
endWith ("z") ، أركض ذلك ، يا gees ، عدد قليل من المستغرب من هؤلاء بحيث يختار
في الظاهر ، يبدو أن هناك ثلاثة أسماء فقط في مجموعة البيانات هذه التي تنتهي بـ "z". وبالتالي
أستطيع أن أقول ، أو يمكن أن تأخذ متعددة
حروف. أستطيع أن أقول ، ينتهي مع ("ly"). أكثر من ذلك بكثير أو أنا ، سأحاول ينتهي مع ("لا"). و
سوف أركض ذلك. أوه ، إذن هناك عدد غير قليل من هؤلاء. يمكنك أن ترى ، أعتقد هذه
كلها أسماء فتاة أيضا. أعني ، هذا هو النمط الثقافي في
من المفترض أن يكون اسم الفتاة أو اسمها "la" اسمًا للفتاة. هذه
هي ، هذا هو مجرد اثنين addit- ، فقط وظيفتين إضافية. ونحن سوف ، كما كنت
نقول ، سننتهي لاستخدامها في الأسماء الموجودة في مجموعة بيانات الطفل ، مجموعة بيانات الطفل.
لكنهم ، سوف يسمحون لنا ببعض المشاكل الأكثر إثارة للاهتمام.
We're gonna get quite a lot, quite a lot of names, beginning with "A". If I
type a lower case "a" here, And I run. We actually get no output. And what's going
on there is in the computer the upper case "A" and the lower case "a", those are
just two different letters. And so in this data the names all begin with an upper
case letter and then all the other letters are lower case. So startingWith("a")
- that's a subtlety, but that has zero results, whereas if I put an upper
case "A" here and run it then we get them all.
Right, and you can even see how yea, they begin with an upper case letter then later
letters are lower case. So you just need to know that on the test. What else was I
going to do here? Let's try "Z". So if I look for startsWith("Z"), then we get all
the names; there's a few there. Or I could narrow it. I could say, oh well, maybe
it has to start with "Za". Then we get fewer. And maybe I could say "Zai".
Then we get down to just four, And then I could say it like, I'll say it like
"Zai"... I don't know, "x". Then I run it, oh
then I get naught. So its poss-, it's certainly possible to write a test where it's just
false. For all 2000 rows and then it just prints nothing. So I'll just back it to "Zai",
and then we just do those. So that the startsWith function, And for these
first examples, we're always going to use it pretty much this way. So we go the row
for the baby data, we get the name out, and then we immediately say .startsWith, to
check the left side of the name. So, as you might guess, there's also a
.endsWith that tests the other, the right hand side of the name. So if I say,
endsWith("z"), I run that, oh gees, surprisingly few of those so that picks
up, apparently there's only three names in this whole data set that end with "z". So
I could say, or I could take multiple
letters. I could say, endsWith("ly"). So a few more Or I, I'll try endsWith("la" ). And
I'll run that. Oh, so then there's quite a few of those. You can see, I think these
are all girl names too. I mean, that, that's just culturally the pattern in
English that, girl name, or "la" is, supposed to be a girl's name. So, these
are, this is just two addit-, just two additional functions. And we'll, as I was
saying, we'll t end to use them for the names in the baby data set, baby data set.
But they're, they're gonna allow us to do some more interesting problems.
يبدأ الجدول مع انتهاء
سابقا فعلنا اختبارات مع
==
و
<
- في هذا القسم القصير ، أضف وظائف startWith / endWith التي تختبر الحروف الموجودة في بداية أو نهاية السلسلة.
بديل ل == ، مفيد جدا لأسماء الطفل
اختبار ما إذا كان حقل الاسم في صف واحد يبدأ بـ "Ab":
if (row.getField ("name"). يبدأWith ("Ab")) {...
اختبار ما إذا كان حقل الاسم في صف واحد ينتهي بـ "zy":
if (row.getField ("name"). endWith ("zy")) {...
وظائف مفيدة ، وليس جزء جافا سكريبت ، ولكن في لغات أخرى
أضفتهم فقط لهذه الفئة
استخدم هذه مع row.getField ("الاسم") للعديد من الأمثلة
تعمل هذه الاختبارات جيدًا مع سلاسل الأسماء التي تم سحبها من بيانات الطفل. هنا يمكننا أن ننظر إلى جميع الأسماء التي تبدأ ب "Ab".
table = new SimpleTable ("baby-2010.csv") ؛
لـ (الصف: الجدول) {
if (row.getField ("name"). يبدأ مع ("Ab")) {
طباعة (الصف).
}
}
المتغيرات لمحاولة أعلاه
يبدأ حقل الاسم بـ "Ab" ، "A" ، "a" (صغيرة) ، "Z" ، "Za" (كل بدوره)
ينتهي حقل الاسم بـ "z" و "ly" و "la" (كل بدوره)
لأغراضنا ، سلاسل دعم أ
s.startsWith ( "أب")
وظيفة ، هنا اختبار ما إذا كانت السلسلة في المتغير s تبدأ بـ "Ab" .. صواب أو خطأ. وبالمثل ، هناك
s.endsWith ( "YZ")
، اختبار هنا إذا كانت السلسلة في متغير s "yz" في نهايتها. (للأسف ، لا تعد هاتان الوظيفتان جزءًا من JavaScript القياسي ؛ لقد جعلتهما يعملان فقط من أجل الشفرة لأنها مفيدة للغاية. هاتان الوظيفتان شائعتان في لغات الكمبيوتر الأخرى.)
كود الحل:
تبين
Table startsWith endsWith
Previously we did tests with
==
and
<
-- in this short section, add the startsWith/endsWith functions which test which letters are at the start or end of a string.
Alternative to ==, very handy for baby names
Test if the name field in a row starts with "Ab":
if (row.getField("name").startsWith("Ab")) { ...
Test if the name field in a row ends with "zy":
if (row.getField("name").endsWith("zy")) { ...
Useful functions, not part Javascript, but in other languages
I added them just for this class
Use these with row.getField("name") for many examples
These tests work very well with the name strings pulled out of the baby data. Here we can look at all the names beginning with "Ab".
table = new SimpleTable("baby-2010.csv");
for (row: table) {
if (row.getField("name").startsWith("Ab")) {
print(row);
}
}
Variants to try above
name field starts with "Ab", "A", "a" (lower case), "Z", "Za" (each in turn)
name field ends with "z", "ly", "la" (each in turn)
For our purposes, strings support a
s.startsWith("Ab")
function, here testing if the string in the variable s starts with the "Ab" .. true or false. Likewise, there is
s.endsWith("yz")
, here testing if the string in variable s has "yz" at its very end. (Sadly, these two functions are not part of standard JavaScript; I made them work just for out code because they are so useful. These two functions are common in other computer languages.)
Solution code:
Show
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
في هذا القسم ، أريد أن أتحدث عن الطريقة التي تسير بها
من تكنولوجيا الأراضي التي تغطي مجرد منزل واحد ،
حتى الإنترنت العالمي ، حيث يمكن لأي كمبيوتر التحدث إلى أي كمبيوتر آخر.
وبالتالي فإن الطريقة التي تعمل بها هي أن تفكر في شبكة الإنترنت العالمية كنوع من نظام الهاتف لأجهزة الكمبيوتر.
حيث تنتشر في كل مكان.
وكل جهاز كمبيوتر لديه عنوان أساسا ،
وأي كمبيوتر قادر على محاولة إجراء مكالمة بيانات إلى أي كمبيوتر آخر.
هذا ... هذا هو المكان الذي أريد الحصول عليه.
كيف يعمل هذا؟
لذلك ، فإن شبكة الإنترنت العالمية تعتمد في الواقع على بعض الأبحاث التي تمولها الحكومة
في 70s من الولايات المتحدة ، وخلق بعض المعايير تسمى TCP / IP.
و TCP / IP هي معايير حرة ومفتوحة. من الواضح أنها كانت ناجحة بشكل كبير.
إنهم ليسوا مالكين أو خاصين لأي بائع ، إنهم فقط ... أحرار في تنفيذ هذه الأشياء.
وأحد الدروس المستفادة من الإنترنت هي أنه ... بالنسبة إلى نوع من البنية التحتية الأساسية من هذا القبيل ،
أنك تريد السماح للعديد من المؤسسات المختلفة باستخدامها وتشعر بأنها تستطيع البناء عليها ،
إن وجود معيار مفتوح هو حقًا الطريق الصحيح.
حسنا. اسمحوا لي أن أتحدث عن كيفية عمل هذا:
لذلك أول شيء يجب معرفته ، عن الإنترنت ،
هو أن كل كمبيوتر متصل بالإنترنت لديه عنوان IP.
إذن ، ما الذي يبدو عليه هذا ... هكذا ، على سبيل المثال ، ها هي صورة الإنترنت الخاصة بي
هكذا على سبيل المثال ، الكمبيوتر في مكتبي. انها عنوان IP هو 171.64.64.166. هذا يحدد جهاز الكمبيوتر الخاص بي.
أكثر من 30 ميلا من هناك ، هناك آلة أخرى أحتفظ بها - codingbat.com -
وله العنوان ، أه ، عنوان IP 173.255.219.70 ، وهلم جرا.
هذه هي عناوين IP V4 ، والتي تستخدم على نطاق واسع للغاية على شبكة الإنترنت اليوم.
وهناك مراجعة تسمى V6 وهذا نوع من الأجنحة ، لكنها لم تقلع بعد.
In this section, I wanna talk about how you go
from a land technology that just covers one house,
up to the world-wide internet, where any computer can talk to any other computer.
So the way this works is you can think of the worldwide internet as sort of a phone system for computers.
Where they're scattered all over.
And every computer has essentially an address,
and any computer is able to attempt to make sort of a data call to any other computer.
That's... that's where I want to get.
How does that work?
So, the world wide Internet is based actually on some Government-funded research
in the 70s from the United States, creating some standards called TCP/IP.
And TCP/IP are free and open standards. They've obviously been enormously successful.
They're not proprietary or specific to any vendor, they're just... anybody's free to implement these.
And one of the lessons of the Internet is that for... for sort of basic infrastructure like that,
that you want to allow a lot of different organizations to use and feel they can build on,
having it be an open standard is really the way to go.
Alright. Let me talk about how this works:
So the first thing to know, about the internet,
is that every computer connected to the Internet has an IP address.
So, what this looks like... so for example, here's my picture of the internet
So for example, the computer in my office. It's IP address is 171.64.64.166. That identifies my computer.
Over 30 miles from there, there's another machine which I maintain - codingbat.com -
and it has the address, uh, the IP address 173.255.219.70, and so on.
So these are IP V4 addresses, which are very widely used on the internet today.
And there is a revision called V6 that's kind of in the wings, but hasn't really taken off yet.
حسنًا ، إذن الشيء الذي يجب معرفته حول عناوين IP هذه ، هو في الواقع أربعة بايت.
هذه أربعة أرقام ، كل منها بين صفر و 255.
لذلك ، شيء آخر يجب معرفته هو أن ... الجزء الأيسر من العنوان يشير إلى الحي تقريبًا.
على سبيل المثال جامعة ستانفورد ، حرم جامعة ستانفورد هو بشكل عام 171.64. شيء ؛
وفي مبني هو 171.64.64. شيء.
لذلك ، على سبيل المثال ، المكتب الموجود بجانب مكتبي:
الكمبيوتر في هناك قد يكون له عنوان 171.64.64 ، ربما .164
لذلك محليا فقط يتغير الرقم الصحيح ،
ويشير الجزء الأيسر إلى مزيد من النوع ، على الإنترنت حيث يوجد هذا الشيء.
لذلك ... إنه مثل أرقام الهواتف بطريقة ما.
لديك رمز البلد ورمز المنطقة ، ولا يمكنك اختيار الخروج من الهواء:
هم نوع من الإشارة إلى أين هذا الرقم.
هناك فيلم مشهور إلى حد ما في فيلم "The Net" ، حيث تكتب Sandra Bullock في عنوان IP: 2375.345.200.
شغلت بقع من الضحك المسرح ، لأنه مع 345 ، كان حجمه أكبر من أن يصلح للبايت.
هذا ، أه ، هذا ليس ... لقد أخرجني بالكامل من الفيلم.
حسنا. لذلك سأعمل على تكبير هذه الصورة ، وشرح كيف تعمل جميع أجزاء هذا العمل.
شيء واحد يجب أن أذكره للتو ، هو أن معظم مناقشتي اليوم ستتحدث عن عناوين IP.
وهذا هو ، كيف يعمل تحت غطاء محرك السيارة.
ولكن لدينا هذه الأسماء المألوفة مثل nick2.stamford.edu ، أو codingbat.com -
هذه هي ما يسمى أسماء النطاقات.
وأسماء النطاق تشكل بفعالية نوع من الاختصار لعناوين IP
لكنهم يستخدمون الكلمات والنقاط العادية فقط ، لذلك من السهل على الشخص أن يتذكرها أو يكتبها.
الطريقة التي تعمل بها ، هناك أساسا دليل عالمي
حيث كلما كتبت في nic2.Stanford.edu ، في الحقيقة يتم ترجمتها.
هناك بحث يحدث ، والذي يترجم ذلك إلى عنوان IP
ثم عنوان IP هو ما يتم استخدامه من هناك إلى الخارج للحزم ، كما سنرى.
فكيف يمكن الحصول على حزمة .... كيف يعمل أي من هذا؟
لذلك أنا بحاجة إلى تقديم هذه الشخصية: جهاز التوجيه.
لذا فإن جهاز التوجيه عبارة عن معدات شبكات متصلة بشبكتين أو أكثر
وأنها خلط الحزم أساسا ذهابا وإيابا.
لذلك ، يمكنه التقاط حزمة من جانب ، وترجمتها عبر شبكة أخرى.
وهكذا ، يمكنك أن تفكر في الإنترنت كنوع من التراكم الجماعي لكل هذه الموجهات.
إذا نظرت إلى مكتبي:
دعنا نقول هنا جهاز الكمبيوتر الخاص بي ، 171.64.64.166 ،
والكمبيوتر الخاص بي متصل ، سأقول 'upstream' إلى جهاز توجيه: 171.64.64.1.
وما يحدث بشكل أساسي هو حصول حاسوبي على خدمة الإنترنت من خلال هذا الموجه.
يوفر نوع جهاز التوجيه هذا خدمة لجهاز الكمبيوتر الخاص بي.
وهذا نوع من التقريب الأول.
ما يحدث هو ، حسناً ، إذا أراد الكمبيوتر الخاص بي إرسال حزمة إلى الإنترنت
إنه فقط يرسل الحزمة ، أقول ... أقول ، قفزة واحدة على هذا الموجه.
ثم ، الآن هي مشكلة أجهزة التوجيه.
سيقوم الموجه بدوره بإرسال الحزمة إلى بعض الموجه التالي ،
أي نوع من ينفجر على شبكة الإنترنت.
وسوف ... سوف أنظر إليه بتفصيل أكثر قليلاً ، حول كيفية عمل ذلك.
Okay, so the thing to know about these IP addresses is, it's actually four bytes.
Those are four numbers, each between zero and 255.
So, another thing to know is that the...the left part of the address roughly indicates the neighbourhood.
So for example Stanford, the Stanford Campus is generally 171.64.something;
and in my building it's 171.64.64.something.
So for example, the office next to mine:
The computer in there might have an address 171.64.64, maybe .164
So locally just the right number changes,
and the left part indicates more sort of, on the Internet where this thing is.
So, it's... it's like phone numbers in a way.
You have the country code and the area code, and you can't just pick 'em out of the air:
they sort of indicate where that number is.
There's a somewhat famous blooper in the movie 'The Net', where Sandra Bullock types in an IP address: 2375.345.200.
Peals of laughter filled the theater, because with 345, it's too big to fit in a byte.
So that's, uh, that's not... it completely takes me out of the movie.
All righty. So I'm gonna zoom in on this picture, explain how all the parts of this work.
One thing I should just mention, is that most of my discussion today will talk about IP addresses.
That is, how it works under the hood.
But we've got these familiar names like nick2.stamford.edu, or codingbat.com -
those are what are called domain names.
And domain names form effectively kind of a shorthand for IP addresses
but they use just regular words and dots, so it's easy for a person to remember or to type.
The way it works is, there's essentially a world wide directory
where whenever you type in nic2.Stanford.edu, really that gets translated.
There's a look up that happens, that translates that into an IP address
and then the IP address is what's used from there on out for the packets, as we'll see.
So how does a packet get.... How does any of this work?
So I need to introduce this character: the router.
So a router is a bit of networking equipment that's connected to two or more networks
and it basically shuffles packets back and forth.
So, it can pick up a packet from one side, and translate it over to another network.
And so, you can think of the internet as sort of built up collectively by all these routers.
So if you look at my office:
Let's say here's my computer, 171.64.64.166,
and my computer's connected, I will say 'upstream' to a router: 171.64.64.1.
And essentially what happens is my computer gets its Internet service through this router.
This router sort of provides service for my computer.
And, that's kind of a first approximation.
What happens is, well, if my computer wants to send a packet out to the internet
it just sends the packet, I'll say... say, one hop over to this router.
And then, now it's the routers problem.
The router will then in turn, send the packet on to some next router,
whatever sort of goes off onto the Internet.
And I'll...I'll look at it in a little more detail, about how that works.
نمط واحد ستلاحظه ، هو أنه في كثير من الأحيان -
لذلك ربما ، كما تعلمون ، ها هو جهاز الكمبيوتر الخاص بي وعدد قليل من أجهزة الكمبيوتر في المكاتب المجاورة لي ...
وفي كثير من الأحيان ، سيكون لجهاز التوجيه عنوان .1 أو .2. سوف يكون الرقم الأكثر اليمين صغيرًا.
ومن ثم خدمة جميع أجهزة الكمبيوتر مع ، كما تعلمون ،
.50 و .166 ، وأي أجهزة كمبيوتر هنا.
حسنا. لذلك اسمحوا لي أن أتناول السؤال.
سأكون عبارة ... السؤال الأكبر هو:
"انظر ، كيف يمكن أن تنتقل الحزمة من جانب من الإنترنت إلى الجانب الآخر؟"
والجواب هو أساسا ، هوب ، هوب ، هوب ، هوب. مثل الأرانب الصغيرة.
لذلك اسمحوا لي أن أريك كيف يعمل هذا.
لذلك ، دعنا نقول هنا ... هنا جهاز الكمبيوتر الخاص بي.
ودعونا نقول أن جهاز الكمبيوتر الخاص بي يريد إرسال حزمة عبر الإنترنت هنا ،
إلى حوالي 30 ميلا ، إلى codingbat.com.
لذا ، فإن ما سيحدث هو أن جهاز الكمبيوتر الخاص بي سيشكل حزمة
الذي رسمته هنا كنوع من الخطوط العريضة المنقطة.
وبدون الخوض في الكثير من التفاصيل ، سأقول أن هذه حزمة IP تستخدم TCP / IP.
وتحتوي حزمة IP على بعض العناوين القياسية.
يحتوي على عنوان "من" وعنوان "إلى" ، وهذه لا تتوافق مع جميع أجهزة الكمبيوتر الموجودة بينهما ،
ولكن إلى ... نقطة النهاية. لذلك ، من أين كان الأصل ، وأين هو في النهاية من المفترض أن يذهب إلى.
لذلك الطريقة التي سيعمل بها هذا ، هي أن جهاز الكمبيوتر الخاص بي سيشكل هذه الحزمة ،
وسوف ترسله قفزة واحدة في اتجاه التيار إلى جهاز الكمبيوتر الخاص بي. الذي رأيناه في الرسم البياني السابق.
الآن ربما يكون جهاز التوجيه هذا بسيطًا إلى حد ما ، فهو يحتوي على عدد قليل من الاتصالات ،
وهكذا سوف ننظر إلى الحزمة ، وعليه فقط أن يقرر:
'حسنا. ما الطريقة التي يمكنني إرسالها للحصول عليها واحدة ... أقرب خطوة إلى وجهتها النهائية؟
الآن بالنسبة لهذا الموجه ، فسوف يرسله بدوره في اتجاه التيار إلى جهاز التوجيه الخاص به ؛ جهاز توجيه أكبر قليلاً وأكثر تكلفة.
هذا قفزة ثانية. وهذه العملية مستمرة ،
حيث ينظر كل جهاز توجيه إلى الحزمة ويتعين عليه اتخاذ قرار:
'حسنا. أي ... بأي طريقة يمكنني إرسال هذا؟
وهذا ... من الصعب معرفة ذلك ، ولكنه ... أمر ممكن.
على وجه الخصوص ، لا يتعين على كل جهاز توجيه معرفة خريطة للإنترنت بالكامل.
انها فقط لمعرفة نوع ... حيها.
من الناحية العملية ، الطريقة التي يعمل بها هذا النوع من الكندية هي ، في الأساس ، يشبه الشعيرات الدموية والشرايين ،
حيث هنا في مكتبي ، هذه مجرد أجهزة صغيرة وأجهزة توجيه صغيرة: لا يحدث الكثير.
لذلك يتم إعادة توجيه نوع الحزمة إلى ما يمكن أن تسميه جهاز التوجيه الأساسي.
في النهاية ، هناك جهاز توجيه كبير للغاية ومكلف للغاية ، والذي يعرف الكثير في الواقع.
وهكذا ، في الصميم ، سيكون هناك قفزة في الاتجاه الجانبي حتى تصل إلى ، كما تعلم ، أقرب أجهزة التوجيه الأساسية إلى الوجهة النهائية.
وبعد ذلك نوع من القفزات مرة أخرى إلى هذا النوع من مستوى الشعرية ،
حتى النهاية يحصل هنا على codingbat.com.
وبالتالي. أعتقد أنه ... من المدهش أنه في كل مرة تشاهد فيها مقطع فيديو على YouTube ، أو ترسل رسالة بريد إلكتروني ،
أو أيا كان ، واستخدام هذا النوع من البيانات مع الحزم ،
الحزم تبذل في الواقع هذا ... هذا العدد الكبير إلى حد ما من القفزات.
مجرد قفزة ، قفزة ، قفزة ، قفزة ، من مكان ... إلى مكان آخر.
من جهاز توجيه واحد إلى آخر للوصول إلى حيث من المفترض أن يذهب في النهاية.
لذلك دعونا نتحدث عن أجهزة التوجيه لفترة ثانية.
كما ذكرت من قبل ، فهم لا يعرفون المسار بالكامل:
كل جهاز توجيه يعرف فقط كيندا محليا ما يجري.
لاحظ أيضًا في هذا الشرح أن جهاز الكمبيوتر الخاص بي لا يعرف أي شيء عن تخطيط الإنترنت.
إنه في الأساس ... يتم تفويضه إلى جهاز التوجيه. انها تقول:
يا جهاز التوجيه ، وهنا حزمة. أنت تعرف ... أنت تعرف كيفية القيام التوجيه. انت تعتني بها.
يجب أن أذكر أن أجهزة التوجيه ... لا يتم تنفيذ جميع خرائط ، بطريقة ما ، الطريقة التي تسير بها الأمور ، بشكل ثابت.
بدلاً من ذلك ، تكون أجهزة التوجيه ديناميكية ؛ انهم دائما نوع من قياس الروابط التي تفرط ،
أو تلك التي تعمل ، أو لا تعمل ، أو أيا كان ،
One pattern you'll notice, is that a lot of times -
so maybe, you know, here's my computer and a few computers in offices next to mine...
and a lot of times the router will have the .1 or .2 address. The... the right-most number will be small.
And then its servicing all the computers with, you know,
.50 and .166, and whatever computers over here.
Alright. So let me get to the question.
I'll, I'll phrase... the biggest question is:
'Look, how does a packet get from one side of the Internet to the other?'
And the answer is basically, hop, hop, hop, hop. Like little bunnies.
So let me show you how this works.
So, let's say here's...here's my computer.
And let's say my computer wants to send a packet across the Internet over here,
to about 30 miles away, to codingbat.com.
So, what's going to happen is, my computer will make up a packet
which I've drawn here as sort of the dotted outline.
And without going into too much detail, I'll say this is an IP packet, used for TCP/IP.
And an IP packet has some addressing that's standard on it.
It has a 'from' address and a 'to' address, and these correspond not to all the computers in between,
but to the...the end points. So, where was it originally from, and where ultimately is it supposed to go to.
So the way this is going to work, is that my computer will make up this packet,
and it'll send it one hop upstream to my computer's router. Which we saw in the earlier diagram.
Now this router is maybe fairly simple, it only has a few connections,
and so it'll look at the packet, and it just has to decide:
'Well. Which way do I send this to get it one...one step closer to its ultimate destination?'
Now for this router, it'll send it in turn upstream to its router; a slightly bigger, more expensive router.
That's a second hop. And this process continues,
where each router looks at the packet and has to make a decision:
'Well. Which...which way do I send this?'
And that is...it's tricky for it to know, but it is...it is feasible.
In particular, each router doesn't have to know a map of the whole Internet.
It just has to sort of know its...its neighbourhood.
As a practical matter, the way this kinda works is, basically it's kinda like capillaries and arteries,
where down here at my office, these are just little machines and little routers: not much going on.
So the packet sort of gets forwarded up to what you would call a core router.
Eventually there's some very large, very expensive router, that actually knows a lot.
And so, on the core it'll sort of hop over sideways until it gets to, you know, the nearest core routers to the ultimate destination.
And then it kind of hops down again to the sort of capillary level,
until eventually it gets over here to codingbat.com.
So. I gues it is...it is surprising that every time you watch a YouTube video, or send an email,
or whatever, and use that sort of data with packets,
the packets are actually making this...this fairly large number of hops.
Just hop, hop, hop, hop, from one...one place to another.
From one router to another to get where it's supposed to go eventually.
So let's talk about routers for a second.
As I mentioned before, they don't know the entire route:
each router just knows kinda locally what's going on.
Also notice in that explanation my computer doesn't know anything about the layout of the internet.
Essentially it's...it's delegated to the router. It says:
'Hey router, here's a packet. You know...you know how to do routing. You take care of it'.
I should mention that routers are... it's not that all the maps of, kind of, which way things go, are done statically.
Instead, the routers are dynamic; they're always sort of measuring which links are overloaded,
or which ones are functioning, or not functioning, or whatever,
وسوف يتوجهون تلقائيًا حول الكسر ، وبالتالي فإن النظام بأكمله لديه نوعًا من جودة الشفاء الديناميكية.
كما ذكرت سابقًا في Ethernet ، تعد أجهزة التوجيه مثالًا آخر على نظام تعاوني موزع.
تعاونهم مع بعضهم البعض ، وهو نوع من العمل معًا ، لحل مشاكل التوجيه لهذه الحزم.
هذا نوع من التفاصيل ، لكن يجب أن أذكر أن هناك بعض عناوين IP الخاصة.
لذلك ، 10. أي ثلاثة أرقام ؛ أو 192.168. شيء ؛ تلك هي عناوين IP المحلية الخاصة ،
وهي غير صالحة على الإنترنت بشكل عام. انهم مجرد العمل على شيء داخل المنظمة.
والطريقة التي تعمل بها هي أنه عندما ... عندما تكون الحزمة مع عنوان محلي خاص مثل هذا
يشق طريقه - قفزة ، قفزة ، قفزة - سوف تتم ترجمتها إلى أن تكون حقيقية .... عنوان IP حقيقي.
السبب الذي ذكرته هو ... هو أن أجهزة توجيه Wi-Fi في كثير من الأحيان سوف تعطي هذه العناوين المحلية الخاصة.
وهكذا إذا كنت ... إذا كنت تتجول باستخدام معداتك الخاصة ، فقد تشاهدها.
لهذا السبب أريد أن أوضح ما كان عليه.
وبالتالي. بالنظر إلى هذا المستوى من التفسير ، يمكنني التحدث عن:
"حسنًا ، ماذا ، ماذا يعني أن أكون ... على الإنترنت؟ أن يكون لديك اتصال بالإنترنت؟
وبشكل عام الطريقة التي تعمل من خلال Wi-Fi أو من خلال Ethernet
هل يعني ذلك ، حسنًا ، أنك قمت بإنشاء ... اتصال ببعض الموجهات الأولية ، ثم ستعمل على التعامل مع حركة المرور لك.
وفي الواقع ، سأحضر هذا إلى هنا.
هذه هي لوحة شبكة Mac ، كما تعلمون.
وهنا لقد قمت بالنقر فوق TCP / IP. لذلك لم أقم بذلك.
سأشير فقط إلى بعض الأشياء الرئيسية هنا:
لذلك ، عند الاتصال بجهاز توجيه Wi-Fi كما قلت هنا ، عمومًا ، سيمنحك عنوان IP بشكل مؤقت.
ستقول: "حسنًا ، حسنًا ، يمكنك استخدام عنوان IP هذا في الوقت الحالي".
لاحظ أن هذا هو عنوان 171.64 ، لذلك في حي ستامفورد. لذلك هذا منطقي.
حتى تحصل على عنوان IP.
أنت أيضًا تميل إلى أن تكون قادرًا على رؤية عنوان IP الخاص بالموجه الذي ترتبط به.
لذلك أنا مرتبط 171.64.71.
لاحظ أيضًا أنه كما قلت ، ينتهي الموجه بـ .1 ، وربما يوفر خدمة لجميع عناوين IP التي تبلغ 171.64.70.
وأخيرًا ، في بعض الأحيان ، سوف يكون هناك .... نظام يسمى DHCP: بروتوكول تكوين المضيف الحيوي.
يعد DHCP مجرد وسيلة لجهاز التوجيه لإبلاغ الكمبيوتر الخاص بي بمجموعة من المعلمات الأخرى حول كيفية عمل الشبكات هنا.
في كثير من الأحيان سترى DHCP جلس ، قائلا "أوه نعم. عندما تتحدث إلى الموجه ، فعل كل ما تقوله بشكل أساسي.
لذلك ، هذا ... هذا ، كما تعلمون ، يمكنك ... يمكنك البحث في لوحة تحكم الشبكة الخاصة بك إذا كنت ترغب في ذلك.
ونأمل أن ترى الكثير من المعلومات في الواقع ... تظهر فعليًا.
حسنا. لذلك ، ما أريد أن أريك ، مجرد نوع من المرح
هي أدوات مساعدة للشبكات الزوجية يمكنك استخدامها للتجول مع هذا قليلاً.
هذا ليس شيئًا تحتاج إلى القيام به بنفسك ، ولكن إذا كنت ترغب في ذلك ، فيمكنك ذلك.
الأدوات المساعدة التي سأظهر لك تسمى "ping" و "trace route".
وعلى أي نوع من أجهزة الكمبيوتر التي تستخدمها ، من المحتمل جدًا وجود بعض الأنواع المتوفرة.
لذلك ، أنا فقط ... أنا ذاهب لكتابة هذه في ... سطر الأوامر.
إذاً ، ping - إذا قلت ، مثل ، ping www. Google.com ، ما يفعله ping هو إرسال حزمة واحدة إلى كمبيوتر آخر
وما تقوله هذه الحزمة بشكل أساسي هو ، "هل أنت موجود؟"
وأجهزة الكمبيوتر ليست مطلوبة للرد على حزم ping ،
ولكن إذا كانوا مهذبين ، فسوف يفعلون ذلك ، وستفعله Google.
وتقوم فقط بإعادة حزمة واحدة تقول بشكل أساسي ، "نعم".
لذلك ، إذا قمت باختبار اتصال جهاز كمبيوتر آخر واستردت الرد ، فهذا أمر يخبرك شيئين.
إنه يخبرك أنه ، جيدًا ، أن الكمبيوتر الآخر قيد التشغيل ويعمل.
ويخبرك أن الشبكة - جميع القفزات المختلفة بينك وبين ذلك الكمبيوتر - تعمل جميعها.
عندما بينغ .... لذلك ، فإنه يرسلها مرة واحدة في الثانية. وما الذي يفعله كل واحد منهم ، هل يشير إلى عدد المللي ثانية التي استغرقها.
لذلك ميلي ثانية واحدة في الألف من الثانية.
وهذا هو إرسال أينما كنت ، كما تعلم ، www.google.com هو ،
انها ترسل حزمة التنقل هناك وهناك التنقل مرة أخرى ،
ويستغرق الأمر ، كما تعلمون ، شيئًا مثل أربعة ميلي ثانية في كل مرة.
لذلك دعونا نرى. لذلك أعتقد أن كلمة "ping" قد دخلت بالفعل إلى حد ما جوهر المفردات الخاصة بالناس النظاميين
من أين تقول ، "حسنًا ، هل ستذهب إلى الحفلة؟ أوه ، سوف أضربهم ونرى ".
إنه مجرد نوع من وسيلة سريعة ، "يا ، هل أنت هناك؟" ، نوع من الرسائل.
لذلك ، يمكنك استخدام الأمر ping إذا كانت شبكتك لا تعمل أو لا تعمل ،
وتريد أن تفعل ، نوعا من مثل التحقق الأساسية قليلا. تعتبر Ping إحدى طرق رؤية ... معرفة ما إذا كانت الأشياء تعمل أم لا.
لذلك يُطلق على قريب من ping ، وهو أداة أكثر تعقيدًا سأستخدمها هنا ، "مسار التتبع".
وانا ذاهب لاستخدام ... سأفعل مسار التتبع إلى codingbat.com.
[بهدوء] عفوًا. انا اسف. هناك. الآن لتتبع الطريق إلى codingbat.com.
وبالتالي. ما مسار التتبع الذي يقوم به ، فهو يقوم بتعيين خرائط القفزات بين جهاز الكمبيوتر الخاص بك وبعض أجهزة الكمبيوتر الأخرى.
وهذا هو نوع من المدهش.
أنا كذلك ... أنا
and they will automatically route around breakage, so the whole system has a sort of dynamic healing quality.
As I mentioned earlier for Ethernet, routers are another example of a distributed collaborative system.
That they cooperate with each other, sort of working all together, to solve the routing problems for these packets.
This is sort of a detail, but I should mention there are certain special IP addresses.
So, 10. any three numbers; or 192.168.something; those are special local IP addresses,
and they're not valid out on the Internet at large. They just sorta work within an organization.
And, the way it works is that when a...when a packet with a special local address like that
is making its way along - hop, hop, hop - It'll get translated to be a real....real IP address.
The reason I mention this is...is that oftentimes Wi-Fi routers will give out these special local addresses.
And so if you...if you're playing around with your own equipment you may see these.
So that's why I want to explain what it was.
So. Given...given that level of explanation, I can talk about:
'Well, what, what does it mean to be...to be on the Internet? To have a connection to the Internet?'
And generally the way that works through Wi-Fi or through Ethernet
is it means, well, you establish a...a connection to some upstream router, and then it's gonna handle traffic for you.
And, actually I'll just bring this up here.
So this is the, you know, the Mac networking panel.
And here I've clicked on TCP/IP. So I didn't just make that up.
I'll just point out some of the major things here:
So when you connect to, let's say, a Wi-Fi router as I have here, generally it'll give you an IP address sorta temporarily.
It'll say: 'Okay, well, you can use this IP address for now'.
Notice this is a 171.64 address, so that's in the Stamford neighborhood. So that makes sense.
So you get an IP address.
You also tend to be able to see the IP address of the router that you're associated with.
So I'm associated with 171.64.71.
Also notice that as I said, the router ends in .1, and it's maybe providing service for all these 171.64.70 IP addresses.
And finally a lot of times you'll.... there's a system called DHCP: Dynamic Host Configuration Protocol.
DHCP is just a way for the router to inform my computer of a bunch of other parameters about how networking works around here.
So very often you'll see DHCP is sat, saying 'Oh yeah. When you talk to the router, basically do whatever it says'.
So, that's...that's, you know, you can...you can look in your own network control panel if you wish.
And hopefully you'll see a lot of the information actually...actually appearing.
All right. So, what I wanna show you, just kind of for fun
is a couple networking utilities that you can use to play around with this a little bit.
This is not something you need to do yourself, but if you wish to, you could.
The utilities I'm gonna show you are called 'ping' and 'trace route'.
And on whatever kind of computer you're on, there's very likely some variant of these available.
So, I'll just, I'm...I'm going to type these in the...the command line.
So, ping - if I say, like, 'ping www. Google.com', what ping does is it sends a single packet out to some other computer
and what that packet basically says is, 'hey are you there?'
And, computers are not required to respond to ping packets,
but if they're polite, they will, and Google does.
And it just sends back a single packet basically saying, 'Yes'.
So if you ping another computer and you get back a response it's really kinda telling you two things.
It tells you that, well, that other computer is switched on and functioning.
And it tells you that the network - all the various hops between you and that computer - that those are all functioning.
When the ping.... So, it sends it once a second. And what it does for each one, is it reports how many milliseconds it took.
So a millisecond is a thousandth of a second.
And so this is sending wherever, you know, www.google.com is,
it's sending a packet hopping over there and hopping back,
and it's taking, you know, something like four milliseconds each time.
So, let's see. So I think 'ping' actually has sort of entered a little bit the gist, the vocabulary of regular people
where you'd say, 'Oh, well, is so-and-so going to the party? Oh, I'll ping them and see'.
It just kind of a means sort of a quick, 'Hey, are you there?', sort of message.
So, you can use ping if your network doesn't seem to be working or whatever,
and you want to do, sort of like a little basic checking. Ping is one way of seeing...seeing if stuff works.
So a relative of ping, a more complicated utility I'm gonna use here, is called 'trace route'.
And I'm going to use... I'll do a trace route to codingbat.com.
[quietly] Oops. Oh, I'm sorry. There. Now to trace route to codingbat.com.
حسنا. لذلك ربما هذا هو أكثر من جهاز التوجيه الأساسية.
كما هو الحال مع ping ، يمكنك أن ترى أنه يمنحك ميلي ثانية ل ... هذا هو الوقت ذهابا وإيابا.
إذن ما حدث هو أن رزمتي جعلت كيندا على عدد قليل من أجهزة توجيه ستامفورد إلى جهاز التوجيه cenic ،
وبعد ذلك ، في مرحلة ما ، في أعقاب تشبيهي الشعري ، من المحتمل أن تشق طريقها إلى الوراء.
Linode هو المكان الذي يتم فيه استضافة codingbat.com - إنها شبكة معطلة على بعض معدات linode
وفي النهاية هنا - هذا في الواقع codingbat.com.
هكذا قلت هذا حوالي 30 ميلا من هنا. وكان ذلك أحد عشر قفزة.
هذا يعطيك ، أيضًا ، بالنسبة لي بعض الشيء شعورًا بالسرعة ، أليس كذلك؟
إذاً ، فهناك أحد عشر قفزة ، أحد عشر قفزة مرة أخرى ... وهي تقوم برحلة ذهابًا وإيابًا بأكملها في 5 آلاف من الثانية.
إذن أنت تشعر بهذا الشعور ، مثل ، "أوه ، صحيح. هذه الأشياء الحاسوبية ، قانون مور ، إنها سريعة جدًا.
إذن ما أردت القيام به ، كنت ألعب معًا ، "حسنًا ، ما هو شيء آخر؟".
في النهاية وجدت ، أه ، poland.pl. بفظاظة هذا ... في بولندا.
إذن ما سنرى - لذلك فإن البحث عن الكنز يستغرق وقتًا أطول هنا -
وبالتالي فإن القفزات القليلة الأولى هي نفسها. حق؟ لا يزال مجرد خزانة في المبنى الخاص بي ، أيا كان.
انه يخرج الى سينيك. هذا هو كل شيء على نفس الشيء.
لكن الآن ، انتهى الأمر ، وهو ينتقل إلى level3.net - لذلك فهذه مجرد شركة كبيرة ... موفر كبير.
وترى المللي ثانية هنا لا تزال منخفضة إلى حد ما.
وعندما يصل الأمر إلى TInet.net 89.194 ، لاحظ ... قفزت الألف من الثانية من ميلي ثانية إلى 202 ميلي ثانية.
أعتقد أن ما تراه هنا - سأسلط الضوء على الخطين - أعتقد أنه كان المحيط الأطلسي. [يضحك]
أعتقد أنه عندما انتقل من موقع Level3.net ، فربما كان هناك رابط ألياف ضوئي كبير حيث ذهب
والآن وصلت إلى أوروبا.
وسرعة الضوء ، كلما دخلت بالفعل في هذا. مثل ، ... يستغرق الأمر وقتًا ، بالميلي ثانية ، للحصول على إشارة بعيدة.
والآن ، بعد أن انتهى الأمر ، أعتقد أن هذا في مكان ما في أوروبا.
والآن تشق طريقها قليلاً ، في النهاية تصل هنا إلى بولندا ،
ويمكنك أن ترى ، كما تعلم ، لقد استغرق الأمر ما يقرب من 200 مللي ثانية.
وهذا وقت رحلة ذهابًا وإيابًا ، لذلك هذا رائع جدًا.
لذلك هناك شيء واحد يمكنك رؤيته هنا ... حسنًا ، جزئيًا يوضح أنه ... نوع من نوعية 'قفزة ، قفزة'.
نعم فعلا. كل حزمة ، كل فيديو يوتيوب ، كل ما رأيته:
كل تلك البيانات كانت تصنع هذا العدد الكبير من القفزات ، نوعًا ما من مكان إلى آخر. هذا هو حقا كيف يعمل.
الشيء الآخر الذي يجب ملاحظته هو أن هذا شيء على بعد 8000 ميلاً؟
لذلك ليس ... أه ، القفزات لا تصعد خطيًا مع المسافة.
هناك ، كما تعلمون ، هناك روابط ألياف ضوئية تحت المحيطات أو أي شيء آخر.
هناك بعض الروابط التي تغطي مساحة كبيرة ، ثم ربما ستصل إلى مدينة معينة ،
ثم لديك الكثير من القفزات في الحرم الجامعي أو أي شيء آخر ، ... للوصول إلى الوجهة النهائية.
لذلك ، هذا ليس شيئًا - ... لا تحتاج إلى تشغيل لعبة ping وتتبع المسار بنفسك.
أريد فقط إظهار ذلك ، ولكن إذا كنت تريد اللعب معهم ، فيمكنك إعطاء فرصة.
وأعتقد أنه بمعنى CS101 ، هذا هو كيف تعمل.
Okay. So this is probably more of a core router.
As with ping, you can see it gives you the milliseconds for... that's the round trip time.
So what's happened is my packet has kinda made it on a few Stamford routers over to the cenic router,
and then at some point, following my artery-capillary analogy, it's probably sorta making its way back down.
Linode is where codingbat.com is hosted - it's a network down on some linode equipment
and eventually here - that's actually codingbat.com.
So as I said that's about 30 miles from here. And so that was eleven hops.
This also gives you, uh, to me a little bit of a sense of how fast it is, right?
So that's eleven hops out, eleven hops back... and it does the entire round trip in 5 thousandths of a second.
So you do get that feeling, like, 'Oh, right. This computer stuff, Moore's Law, it's pretty fast.'
So what I wanted to do, I was sort of playing around with, 'well, what's something further?'.
So eventually I found, uh, poland.pl. Oviously this is...is in Poland.
So what we'll see - so the treasure hunt's taking a little longer here -
so the first few hops are the same. Right? It's still just some closet in my building, whatever.
It gets out to the cenic. This is all sorta the same.
But now it's going over, it's routing over to level3.net - so that's just a big...a big provider.
And you see the milliseconds here are still fairly low.
And when it gets to the TInet.net 89.194, notice the...the milliseconds has jumped up from 2 milliseconds to 202 milliseconds.
I think what you see here - I'll highlight the two lines - I think that was the Atlantic Ocean. [laugh]
I think when it went from this Level3.net, probably then there was a big fiber-optic link where it went
and now it's made its way to Europe.
And the speed of light, whenever it does actually enter into this. Like, it...it does take time, in milliseconds, to get a signal that far.
So, now that it's over, I'm just guessing, this is somewhere in Europe.
And now it makes its way over a little bit, it eventually gets over here to Poland,
and you can see, you know, it took something like 200 milliseconds.
And that's a round trip time, so that's pretty neat.
So one thing you can see here... well,partly it just shows that...the sort of 'hop, hop' quality.
Yes. Every packet, every YouTube video, everything you've seen:
all that data was making that sort of crazy large number of hops, sort of getting from place to place. That really is how it works.
The other thing to notice is that this is something like, 8000 miles away?
So it's not... Uh, hops don't just go up linearly with distance.
There are, you know, there are cer- there's fiber optic links under the oceans or whatever.
There are certain links that are, that cover a vast amount of distance, and then maybe it'll get down to a particular city,
and then have a lot of hops on a campus or whatever, to...to get to the final destination.
So, that's not something - ...you don't need to run ping and trace route yourself.
I just want to demonstrate those, but if you want to play with them, you can give 'em a shot.
And I guess in the CS101 sense, like, that's really how it works.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
الإنترنت - TCP / IP
الإنترنت - معايير TCP / IP
سابقا .. الشبكة المحلية ، على سبيل المثال إيثرنت ، واي فاي ، منزل واحد
الإنترنت - شبكة عالمية
مثل نظام الهاتف لأجهزة الكمبيوتر
- كل كمبيوتر له عنوان فريد
- يمكن لكل كمبيوتر محاولة "استدعاء" أي كمبيوتر آخر
معايير TCP / IP ، 1974 ، بحث ترعاه الحكومة
معايير حرة ومفتوحة ، بائع محايد - نمط ناجح للبنية التحتية
تقوم أمثلة LAN السابقة بتوصيل أجهزة الكمبيوتر كلها على نفس الشبكة المحلية. سنقوم الآن بتوسيع نطاق المشكلة لإرسال حزم بين أي جهازي كمبيوتر على الأرض.
تعتمد الإنترنت في جميع أنحاء العالم على مجموعة معايير TCP / IP (بروتوكول التحكم في الإرسال / بروتوكول الإنترنت) التي تحل المشكلة الأكبر المتمثلة في إرسال الحزم بين أجهزة الكمبيوتر عبر الإنترنت بالكامل. هذه معايير حرة ومفتوحة ومحايدة للبائع ، والتي ربما كانت السبب وراء نجاحها بشكل لا يصدق.
عنوان IP
كل كمبيوتر على شبكة الانترنت لديه عنوان IP
هنا تبحث في عناوين IP v4 ، v6 في الأفق
مثلا 171.64.64.166
4 بايت
الجزء الأيسر يشفر "الحي" على شبكة الإنترنت
تماما مثل الهاتف ، 650-725-0000
مثلا 171.64.xxx.xxx بشكل عام حرم ستانفورد
مثلا 171.64.64.xxx بلدي الطابق بناء غيتس
ساندرا بولوك تتفتح في ذا نت: "23.75.345.200"
وداعا جائزة أوسكار!
أجهزة الكمبيوتر مع عناوين بروتوكول الإنترنت
كل كمبيوتر على شبكة الإنترنت لديه "عنوان IP" يحدده (مثل رقم الهاتف). عنوان IP هو 4 بايت ، مكتوب بين النقاط ، مثل "171.64.2.3". يشفر الجزء الأيسر من العنوان جزئيًا حيث يوجد عنوان IP هذا في شبكة الإنترنت بالكامل - على سبيل المثال أي 171.64. (أي شيء) هو جزء من Stanford (مثل رمز المنطقة لرقم الهاتف). وبشكل أكثر تحديدًا ، في الجزء الخاص بي من مبنى Gates ، تبدأ جميع عناوين IP 171.64.64.XX تختلف فقط في البايت الأخير.
ساندرا بولوك: هناك فيلم "ذا نت" حيث يظهر عنوان IP "23.75.345.200". هذا ليس عنوانًا صالحًا ، لأن 345 أكبر من أكبر قيمة ممكنة للبايت وهي 255.
أسماء النطاقات
أسماء المجال ، أسماء بديلة أساسا لإدارات IP
www.google.com
nick2.stanford.edu
أسماء النطاقات سهلة للأشخاص على تذكرها وكتابتها
يمكن لنظام المجال البحث عن عنوان IP من اسم مجال
لذلك عند استخدام اسم مجال ، يتم البحث عنه للحصول على عنوان IP للحزم الفعلية
راوتر
The Internet - TCP/IP
Internet - TCP/IP Standards
Previously .. LAN, e.g. ethernet, Wi-Fi, one house
Internet - world-wide network
Like a phone system for computers
--Every computer has a unique address
--Every computer can try to "call" any other computer
TCP/IP Standards, 1974, government sponsored research
Free and open standards, vendor neutral -- successful pattern for infrastructure
The previous LAN examples connect computers all on the same LAN. Now we will scale the problem up to send packets between any two computers on earth.
The worldwide Internet is built on the TCP/IP family of standards (Transmission Control Protocol / Internet Protocol) which solves the larger problem of sending packets between computers across the whole internet. These are free and open, vendor-neutral standards which is probably the reason they have been so incredibly successful.
IP Address
Every computer on the internet has an IP address
Here looking at IP v4 addresses, v6 on the horizon
e.g. 171.64.64.166
4 bytes
Left part encodes "neighborhood" on internet
Just like phone, 650-725-0000
e.g. 171.64.xxx.xxx generally Stanford campus
e.g. 171.64.64.xxx my floor of Gates building
Sandra Bullock blooper in The Net: "23.75.345.200"
Goodbye Oscar award!
computers with ip addresses
Every computer on the internet has an "IP address" that identifies it (like a phone number). The IP address is 4 bytes, written between dots, like "171.64.2.3". The left part of the address encodes in part where that IP address is in the whole internet -- for example any 171.64.(anything) is part of Stanford (like the area code of a phone number). More specifically, in my part of the Gates building, all the IP addresses begin 171.64.64.XX varying only in that last byte.
Sandra Bullock: there's a blooper in the movie The Net where the IP address "23.75.345.200" is shown. This is not a valid address, since 345 is larger than the largest possible byte value which is 255.
Domain Names
Domain names, essentially alternate names for IP addrs
www.google.com
nick2.stanford.edu
Domain names are easy for people to remember and type
Domain system can look up an IP addr from a domain name
So when you use a domain name, it is looked up to get an IP addr for the actual packets
Router
راوتر
جهاز التوجيه لديه اتصالات متعددة ، نسخ / طرق الحزم بينهما
كمبيوتر مكتبي هو في 171.64.64.166
يربط هذا الكمبيوتر "المنبع" بالموجه 171.64.64.1
يعالج جهاز التوجيه حركة المرور لعدد قليل من أجهزة الكمبيوتر المحلية
الجانب الأيسر من الكمبيوتر وعنوان IP لجهاز التوجيه عادة نفس - حي نفسه
جهاز التوجيه وأجهزة الكمبيوتر الخاصة به
تتمثل الطريقة الأكثر شيوعًا لوجود جهاز كمبيوتر على "الإنترنت" في إنشاء اتصال مع "جهاز توجيه" موجود بالفعل على الإنترنت. يقوم الكمبيوتر بإنشاء اتصال عبر ، على سبيل المثال ، شبكة إيثرنت لتوصيل الحزم بالموجه. جهاز التوجيه هو "المنبع" للكمبيوتر ، توصيل الكمبيوتر بالإنترنت بالكامل. على سبيل المثال ، يحتوي الكمبيوتر في مكتب Stanford الخاص بي على عنوان IP 171.64.64.166 ، ولديه اتصال إيثرنت أحادي الاتجاه بموجهه الأولي في 171.64.64.1 ، ويعالج جهاز التوجيه هذا الحزم للكمبيوتر الخاص بي. غالبًا ما ينتهي عنوان IP الخاص بالموجه بـ .1 ، مثل 171.64.64.1 الخاص بالموجه. عادةً ما سيبحث عنوان IP الخاص بالكمبيوتر وجهاز التوجيه الخاص به في الجانب الأيسر ، نظرًا لأنهما يقعان في "حي" الإنترنت نفسه.
كيف يمكن الحصول على حزمة عبر الإنترنت؟
الجواب: هوب هوب هوب هوب هوب
العائدات الحزمة بواسطة القفزات متعددة
افترض أن 171.64.64.166 يرسل حزمة إلى 173.255.219.70
حزمة IP مع علامة نهائية من: / إلى: addrs IP
الفكرة الأساسية: الحزمة تستكمل قفزة واحدة في كل مرة
قفز 1: 171.64.64.166 يرسل الحزمة حتى جهاز التوجيه الخاص به
قفز 2: 171.64.64.1 يرسل الحزمة حتى جهاز التوجيه الأكبر
قفزة هوب هوب ، وصولا إلى الوجهة ، 20-30 القفزات عادة
القياس: مصدر شعري يصل إلى الشريان الرئيسي ، مرارا ، وصولا إلى شعري الوجهة
لنفترض أن جهاز الكمبيوتر الخاص بي على 171.64.64.166 يريد إرسال حزمة إلى كمبيوتر على 173.255.219.70 في مكان ما خارج الإنترنت (في الواقع هذا هو خادم codingbat.com الذي أديره). يتكون الإنترنت بشكل أساسي من شبكة كبيرة من أجهزة التوجيه التي تتحدث مع بعضها البعض.
1. يعد جهاز الكمبيوتر الخاص بي حزمة IP والتي تتضمن بشكل خاص من: / إلى: المعلومات كعناوين IP ، مثل هذا: (حزمة IP من: 171.64.64.166 إلى: 173.255.219.70 بيانات بيانات البيانات).
2. يرسل جهاز الكمبيوتر الخاص بي هذه الحزمة IP إلى جهاز التوجيه الخاص بي ، قفزة واحدة ، عبر الإيثرنت. هذا هو "القفزة الأولى" للحزمة في رحلتها.
3. ينظر جهاز التوجيه 171.64.64.1 إلى: / من: من الحزمة ويعيد توجيهه إلى جهاز التوجيه التالي ، قفزة واحدة أقرب إلى وجهتها النهائية. في الأساس ، يحتوي جهاز التوجيه على جهاز توجيه upstream خاص به وهو أكبر ويعرف المزيد عن تخطيط الإنترنت. يتم توجيه الحزمة ، قفزة واحدة في كل مرة ، حتى تصل إلى وجهتها النهائية. لا يحتاج كل جهاز توجيه إلى معرفة المسار بالكامل إلى الوجهة ؛ يحتاج كل جهاز توجيه فقط إلى معرفة طريقة إرسال الحزمة لتقريبها خطوة واحدة من وجهتها. تنظر الموجهات إلى الجزء الأيسر من عنوان IP للحصول على الحزمة إلى الحي الأيمن - 173.255.xx - مع تشغيل الجزء الأيمن من العنوان - xx219.70 - فقط عندما تكون الحزمة بالقرب من نهايتها المكان المقصود.
تحليل التوجيه
يعرف كل جهاز توجيه ما يكفي لتحديد القفزة التالية ، وليس المسار بالكامل
الكمبيوتر الأصلي لا يعرف عادة الكثير ، المفوض إلى أجهزة التوجيه
أجهزة التوجيه "الأساسية" ، نحو الوسط
- العديد من الاتصالات
- قدرة أعلى
--أغلى
- أكثر قرارات التوجيه معقدة
تقوم أجهزة التوجيه بقياس وظيفة / انقطاع الاتصال طوال الوقت ، وتوجيهها
أجهزة التوجيه هي نظام توزيع مشترك آخر
يشبه توجيه الحزمة من جهاز الكمبيوتر الخاص بك نظامًا شعريًا / شريانيًا .. جهاز الكمبيوتر الخاص بك معطّل على مستوى الشعيرات الدموية ، وتُرسل الحزمة إلى الشرايين الأكبر والأكبر ، وتمتد إلى المنطقة الصحيحة ، ثم تنخفض إلى الشعيرات الدموية الأصغر والأصغر مرة أخرى ، تصل أخيرًا إلى وجهتها. تضع الوجهة النهائية جميع الحزم معًا في الترتيب الصحيح لاستعادة ملف الصورة الأصلي أو أيًا كان. تحتوي أجهزة التوجيه الموجودة في النهايات على تكوين تكميلي للتيار النهائي / المتلقين للمعلومات ، وبالتالي فإن القفزة التالية للحزمة بسيطة جدًا. تميل أجهزة التوجيه "الأساسية" الأكثر مركزية إلى العديد من الاتصالات الصادرة المحتملة ، لذلك لديهم خيار أكثر تعقيدًا حول أي رابط لاستخدامه في القفزة التالية.
تقوم أجهزة التوجيه ، مجتمعة ، بقياس الشبكات التي يمكن الوصول إليها عبر الارتباطات ، وتعديل الارتباطات بشكل حيوي لاستخدامها لكل حزمة. يتمثل أحد المقاييس البسيطة في توجيه الحزم بالطريقة التي تأخذ أقل عدد من القفزات. في الواقع ، المقاييس المستخدمة أكثر تعقيدًا من هذا. يتسم نظام التوجيه بالمرونة مع تعطل أجهزة الموجه ، والحمل الزائد لبعض الروابط بسبب حركة المرور العادية ، والروابط تنخفض. يمكن أن يتغير المسار الذي سلكته حزمة IP من دقيقة إلى دقيقة. تعتبر أجهزة التوجيه مثالًا آخر على النظام الموزع والمشترك. تتمثل النكتة القديمة في أن الحفار هو المفترس الطبيعي لحزمة IP في البرية ، حيث إن البناء في بعض الأحيان يمتد عبر كابل بيانات مهم ، ويكسر فجأة رابطًا قيد الاستخدام. أجهزة التوجيه "حول الطريق" مثل هذا الضرر تلقائيا.
Router
Router has multiple connections, copies/routes packets between them
My office computer is at 171.64.64.166
That computer connects "upstream" to router 171.64.64.1
That router handles traffic for a few local computers
Left side of computer and router IP addresses typically the same -- same neighborhood
router and its computers
The most common way for a computer to be "on the internet" is to establish a connection with a "router" which is already on the internet. The computer establishes a connection via, say, ethernet to communicate packets with the router. The router is "upstream" of the computer, connecting the computer to the whole internet. For example, the computer in my Stanford office has IP address 171.64.64.166, and it has a one-hop ethernet connection to its router upstream at 171.64.64.1, and this router handles packets for my computer. Often the router's IP address will end in .1, such as my router's 171.64.64.1. Typically the IP address of the computer and its router will look at the same on the left side, since they are in the same "neighborhood" of the internet.
How Does a Packet Get Across The Internet?
Answer: Hop Hop Hop Hop Hop
packet proceeds by multiple hops
Suppose 171.64.64.166 sends a packet over to 173.255.219.70
IP packet marked with ultimate From:/To: IP addrs
Key idea: packet proceeds one hop at a time
Hop 1: 171.64.64.166 sends packet up to its router
Hop 2: 171.64.64.1 sends packet up to its bigger router
Hop hop hop, over to destination, 20-30 hops typically
Analogy: source capillary up to major artery, over, and down to destination capillary
Suppose my computer at 171.64.64.166 wants to send a packet to a computer at 173.255.219.70 somewhere out on the internet (actually that's the codingbat.com server I administer). The Internet is essentially made of a big web of routers talking to each other.
1. My computer prepares an IP packet which includes in particular From:/To: information as IP addresses, like this: (IP Packet From:171.64.64.166 To:173.255.219.70 data data data data).
2. My computer sends that IP packet to my upstream router, one hop, over ethernet. This is the "first hop" of the packet on its journey.
3. The 171.64.64.1 router looks at the To:/From: of the packet and forwards it to the next router, one hop closer to its ultimate destination. Essentially, the router has its own upstream router which is bigger and knows more about the layout of the internet. The packet is forwarded, one hop at a time, until it reaches its ultimate destination. Each router does not need to know the whole route to the destination; each router just needs to know which way to send the packet to get it one-hop closer to its destination. The routers look at the left part of the IP address to get the packet to the right neighborhood -- 173.255.x.x -- with the right part of the address -- x.x.219.70 -- coming into play only when the packet is near its ultimate destination.
Router Analysis
Each router knows enough to figure the next hop, not the whole route
The original computer does not typically know much, delegating to routers
"Core" routers, towards the middle
--Many connections
--Higher capacity
--More expensive
--More complicated routing decisions
Routers measure connection functionality/breakage all the time, route around
Routers are another distributed, collaborative system
The routing of a packet from your computer is like a capillary/artery system .. your computer is down at the capillary level, your packet gets forwarded up to larger and larger arteries, makes its way over to the right area, and then down to smaller and smaller capillaries again, finally arriving at its destination. The ultimate destination puts all the packets back together in the right order to recover the original image file or whatever. The routers at the ends have a trivial upstream/downstream configuration, so the next hop for a packet is pretty simple. More central "core" routers tend to have several possible outgoing connections, so they have a more complicated choice about which link to use for the next hop.
The routers, collectively, measure what networks are reachable over what links, and dynamically adjust what links to use for each packet. One simple metric would be to route packets the way that takes the fewest number of hops. In reality, the metrics used are more complex than this. The routing system resilient to router hardware failures, overloading of certain links due to normal traffic, and links going down. The path taken by an IP packet can change from minute to minute. The routers are another example of a distributed, collaborative system. The old joke is that the backhoe is the IP packet's natural predator in the wild, as construction will sometimes slice through an important data cable, suddenly breaking a link in use. The routers "route around" such damage automatically.
Traceroute هو برنامج سيحاول التعرف على جميع أجهزة التوجيه الموجودة بينك وبين بعض أجهزة الكمبيوتر الأخرى الموجودة على الإنترنت - مما يدل على جودة قفزة هوب هوب للإنترنت. تحتوي معظم أجهزة الكمبيوتر على نوع من الأداة المساعدة "traceroute" المتاحة إذا كنت ترغب في تجربتها بنفسك (غير مطلوبة). تكون بعض أجهزة التوجيه مرئية للتتبع وبعضها لا ، لذلك لا توفر إخراجًا موثوقًا به تمامًا. ومع ذلك ، فهو انعكاس أنيق لجودة قفزة الهيب هوب للإنترنت. إليك مثال على التتبع من مكتبي:
$ traceroute -q 1 codingbat.com # أنا اكتب في أمر هنا
تتبع إلى codingbat.com (173.255.219.70) ، 64 القفزات كحد أقصى ، 52 حزم بايت
1 yoza-vlan70 (171.64.70.2) 2.039 مللي ثانية
2 bbra-rtr-a (171.64.255.129) 0.932 مللي ثانية
3 - الحدود الدنيا (172.20.4.2) 3.174 مللي ثانية
4 dca-rtr (68.65.168.51) 27.085 مللي ثانية
5 dc-svl-agg1--stanford-10ge.cenic.net (137.164.50.157) 2.485 ms
6 dc-oak-core1--svl-agg1-10ge.cenic.net (137.164.47.123) 3.262 ms
7 dc-paix-px1-- oak-core1-ge.cenic.net (137.164.47.174) 4.046 مللي ثانية
8 إعصار - paix-px1-ge.cenic.net (198.32.251.70) 14.252 مللي ثانية
9 10gigabitethernet1-2.core1.fmt1.he.net (184.105.213.65) 9.117 مللي ثانية
10 linode-llc.10gigabitethernet2-3.core1.fmt1.he.net (64.62.250.6) 4.975 ms
11 li229-70.members.linode.com (173.255.219.70) 4.761 ms
$ traceroute -q 1 poland.pl
تتبع المسار إلى poland.pl (193.59.194.101) ، 64 قفزة كحد أقصى ، 52 حزمة بايت
1 yoza-vlan70 (171.64.70.2) 1.573 مللي ثانية
2 bbra-rtr-a (171.64.255.129) 1.106 مللي ثانية
3 - الحدود الدنيا (172.20.4.2) 32.970 مللي ثانية
4 dca-rtr (68.65.168.51) 1.530 مللي ثانية
5 dc-svl-agg1--stanford-10ge.cenic.net (137.164.50.157) 1.359 ms
6 dc-svl-core1--svl-agg1-10ge.cenic.net (137.164.47.121) 1.967 ms
7 dc-svl-isp1--svl-core1-10ge.cenic.net (137.164.47.132) 1.728 ms
8 xe-4-1-2.edge1.sanjose1.level3.net (4.53.16.185) 1.687 ms
9 vlan60.csw1.sanjose1.level3.net (4.69.152.62) 2.210 ms
10 ae-61-61.ebr1.sanjose1.level3.net (4.69.153.1) 1.637 ms
11 ae-2-2.ebr2.newyork1.level3.net (4.69.135.186) 70.263 ms
12 ae-72-72.csw2.newyork1.level3.net (4.69.148.38) 72.573 ms
13 ae-91-91.ebr1.newyork1.level3.net (4.69.134.77) 72.235 ms
14 ae-42-42.ebr2.london1.level3.net (4.69.137.69) 139.832 ms
15 ae-58-223.csw2.london1.level3.net (4.69.153.138) 146.678 ms
16 ae-21-52.car1.london1.level3.net (4.69.139.98) 172.864 ms
17 212.113.16.110 (212.113.16.110) 139.842 مللي ثانية
18 ae1-0.ams-koo-score-1-re0.interoute.net (84.233.190.57) 169.460 ms
19 ae0-0.ams-koo-score-2-re0.interoute.net (84.233.190.2) 182.792 ms
20 ae1-0.ber-alb-score-1-re0.interoute.net (84.233.190.22) 168.766 ms
21 gi1-0.waw-002-access-1002.interoute.net (84.233.213.33) 168.403 ms
22 po6-0.waw-002-access-1001.interoute.net (84.233.213.45) 170.038 ms
23 195.81.72.214 (195.81.72.214) 168.413 مللي ثانية
24 pkp-gw-ae0-100.core.nask.pl (195.187.255.156) 179.974 مللي ثانية
25 pw-gw0-ae1-100.core.nask.pl (195.187.255.152) 168.538 مللي ثانية
26 helm-at2-0-1.nask.waw.pl (194.92.0.158) 169.701 ms
27 193.59.194.101 (193.59.194.101) 169.830 مللي ثانية
الأرقام الموجودة أسفل الجانب الأيسر هي عدد "القفزات" لهذا الجهاز. الأرقام "ms" هي عدد المللي ثانية (1 مللي ثانية = ألف من الثانية) التي استغرقتها للإرسال / الرد. لاحظ أنه كلما ابتعدت القفزات ، استغرق الأمر ما يقرب من ملي ثانية. أول القفزات هي عناوين Stanford ، ثم يمضي الطريق على بعض الموفرين ، حتى يصل إلى Linode ، وهي الشركة التي توفر الأجهزة التي يعيش فيها codingbat.com حاليًا. لغز صغير: يبدو أن القفزة الأولى يجب أن تكون 171.64.64.1 وهو أول جهاز توجيه من مكتبي ؛ يبدو أن جهاز التوجيه غير مرئي لتتبع المسار.
Traceroute is a program that will attempt to identify all the routers in between you and some other computer out on the internet - demonstrating the hop-hop-hop quality of the internet. Most computers have some sort of "traceroute" utility available if you want to try it yourself (not required). Some routers are visible to traceroute and some not, so it does not provide completely reliable output. However, it is a neat reflection of the hop-hop-hop quality of the internet. Here's an example traceroutes from my office:
$ traceroute -q 1 codingbat.com # I type in a command here
traceroute to codingbat.com (173.255.219.70), 64 hops max, 52 byte packets
1 yoza-vlan70 (171.64.70.2) 2.039 ms
2 bbra-rtr-a (171.64.255.129) 0.932 ms
3 boundarya-rtr (172.20.4.2) 3.174 ms
4 dca-rtr (68.65.168.51) 27.085 ms
5 dc-svl-agg1--stanford-10ge.cenic.net (137.164.50.157) 2.485 ms
6 dc-oak-core1--svl-agg1-10ge.cenic.net (137.164.47.123) 3.262 ms
7 dc-paix-px1--oak-core1-ge.cenic.net (137.164.47.174) 4.046 ms
8 hurricane--paix-px1-ge.cenic.net (198.32.251.70) 14.252 ms
9 10gigabitethernet1-2.core1.fmt1.he.net (184.105.213.65) 9.117 ms
10 linode-llc.10gigabitethernet2-3.core1.fmt1.he.net (64.62.250.6) 4.975 ms
11 li229-70.members.linode.com (173.255.219.70) 4.761 ms
$ traceroute -q 1 poland.pl
traceroute to poland.pl (193.59.194.101), 64 hops max, 52 byte packets
1 yoza-vlan70 (171.64.70.2) 1.573 ms
2 bbra-rtr-a (171.64.255.129) 1.106 ms
3 boundarya-rtr (172.20.4.2) 32.970 ms
4 dca-rtr (68.65.168.51) 1.530 ms
5 dc-svl-agg1--stanford-10ge.cenic.net (137.164.50.157) 1.359 ms
6 dc-svl-core1--svl-agg1-10ge.cenic.net (137.164.47.121) 1.967 ms
7 dc-svl-isp1--svl-core1-10ge.cenic.net (137.164.47.132) 1.728 ms
8 xe-4-1-2.edge1.sanjose1.level3.net (4.53.16.185) 1.687 ms
9 vlan60.csw1.sanjose1.level3.net (4.69.152.62) 2.210 ms
10 ae-61-61.ebr1.sanjose1.level3.net (4.69.153.1) 1.637 ms
11 ae-2-2.ebr2.newyork1.level3.net (4.69.135.186) 70.263 ms
12 ae-72-72.csw2.newyork1.level3.net (4.69.148.38) 72.573 ms
13 ae-91-91.ebr1.newyork1.level3.net (4.69.134.77) 72.235 ms
14 ae-42-42.ebr2.london1.level3.net (4.69.137.69) 139.832 ms
15 ae-58-223.csw2.london1.level3.net (4.69.153.138) 146.678 ms
16 ae-21-52.car1.london1.level3.net (4.69.139.98) 172.864 ms
17 212.113.16.110 (212.113.16.110) 139.842 ms
18 ae1-0.ams-koo-score-1-re0.interoute.net (84.233.190.57) 169.460 ms
19 ae0-0.ams-koo-score-2-re0.interoute.net (84.233.190.2) 182.792 ms
20 ae1-0.ber-alb-score-1-re0.interoute.net (84.233.190.22) 168.766 ms
21 gi1-0.waw-002-access-1002.interoute.net (84.233.213.33) 168.403 ms
22 po6-0.waw-002-access-1001.interoute.net (84.233.213.45) 170.038 ms
23 195.81.72.214 (195.81.72.214) 168.413 ms
24 pkp-gw-ae0-100.core.nask.pl (195.187.255.156) 179.974 ms
25 pw-gw0-ae1-100.core.nask.pl (195.187.255.152) 168.538 ms
26 helm-at2-0-1.nask.waw.pl (194.92.0.158) 169.701 ms
27 193.59.194.101 (193.59.194.101) 169.830 ms
The numbers down the left side are the number of "hops" to that machine. The "ms" figures are the number of milliseconds (1 ms = 1 thousandth of a second) it took for the send/reply. Notice that as the hops get further away, it does roughly take more milliseconds. The first few hops are Stanford addresses, then the route goes over some provider, until it arrives at Linode, which is the company that provides the hardware where codingbat.com currently lives. Small mystery: it seems like the first hop should be 171.64.64.1 which is the first router from my office; apparently that router is invisible to traceroute.
LocationLocation Name
1345 Main St San Francisco, CA Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi. |